Need help with javascript for a auto embed script I'm working on.

lostkid

Active member
Mar 18, 2021
131
54
28
25
I'm writing a auto embed script for the MTDB script to auto embed my StreamAPI. I've written the script in php but i had to use some javascript and jquery to embed the urls in portions and return the results while the script is runnig. I just need some additional assitance adding more functionality with the javascript and jquery. I don't know much javascript and would appreciate the help.


ScreenShot_20210501224422.png
 

bluvia

Active member
Feb 6, 2021
236
82
28
hi @lostkid

You can check below plugins and codes ;



and training document for jquery

 

lostkid

Active member
Mar 18, 2021
131
54
28
25
hi @lostkid

You can check below plugins and codes ;



and training document for jquery


I appreciate you trying to help but none of these is of any use. I read the code for the WP plugin and it's just one php file that templates the iframe for the embed. While my script have a lot more to it.

ScreenShot_20210503120536.png

use jquery ajax, or fetch or axios to do it

At the moment I'm using this jquery ajax code i got from stackoverflow

ScreenShot_20210503121019.png

I just need the stop function to work as well as getting the values in a form to set the stop and start variables.
 

ngepetlo

Member
Nov 26, 2020
36
15
8
I appreciate you trying to help but none of these is of any use. I read the code for the WP plugin and it's just one php file that templates the iframe for the embed. While my script have a lot more to it.

ScreenShot_20210503120536.png



At the moment I'm using this jquery ajax code i got from stackoverflow

ScreenShot_20210503121019.png

I just need the stop function to work as well as getting the values in a form to set the stop and start variables.
so you want when you click button stop the ajax stop loading ?
or you want send value 10 to embed function when you click button stop ?
 

ngepetlo

Member
Nov 26, 2020
36
15
8
screenshot_20210503121019-png.76350


you don't need setTimeout inside runembed because the function will only run when you click button start,
and you are using settimeout without cleartimeout, it will make the ajax keep sending to embed.php for every 2 second
 

lostkid

Active member
Mar 18, 2021
131
54
28
25
so you want when you click button stop the ajax stop loading ?
or you want send value 10 to embed function when you click button stop ?
I want the settimeout to stop when i click the stop button. and i need it to grab some input from a form
 

ngepetlo

Member
Nov 26, 2020
36
15
8
I want the settimeout to stop when i click the stop button. and i need it to grab some input from a form
you don't need setTimeout inside runembed because the function will only run when you click button start,
and you are using settimeout without cleartimeout, it will make the ajax keep sending to embed.php for every 2 second,
but if you just want to stop the settimeout whenever you click stop button,use this code
JavaScript:
let delay;
function runEmbed(){
embed()
delay = setTimeout(runEmbed, 2000);


}
$( "#stop" ).click(function() {
clearTimeout(delay);
});
 
Last edited:
  • Like
Reactions: lostkid

lostkid

Active member
Mar 18, 2021
131
54
28
25
you don't need setTimeout inside runembed because the function will only run when you click button start,
and you are using settimeout without cleartimeout, it will make the ajax keep sending to embed.php for every 2 second
I want it to run every 2 seconds it make inserts the embed and returns the results in portions.
I tried using the clearTimeout function in different ways but it didnt work. Maybe setInterval might work better.

This is the embed.php file.

ScreenShot_20210503130059.png
 

ngepetlo

Member
Nov 26, 2020
36
15
8
I want it to run every 2 seconds it make inserts the embed and returns the results in portions.
I tried using the clearTimeout function in different ways but it didnt work. Maybe setInterval might work better.

This is the embed.php file.

ScreenShot_20210503130059.png
have you tried using the code below?
JavaScript:
let delay; // this is important to make cleartimeout work
function runEmbed(){
embed()
delay = setTimeout(runEmbed, 2000);
}
$( "#stop" ).click(function() {
clearTimeout(delay);
});

or using set interval
JavaScript:
let delay;// this is important to make clearinterval work
function runEmbed(){
embed();
delay = setInterval(embed, 2000);

}

$( "#start" ).click(function() {
  runEmbed()
});
$( "#stop" ).click(function() {
clearInterval(delay);
});
 
Last edited:
  • Love
Reactions: lostkid

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu