Skip to content Skip to sidebar Skip to footer

How To Manage Ajax Code To Display Image And Video Using Switch Case On Html

I have 2 tables(image and video). In my HTML code I have three buttons, named slide_image, video, ans single_image. Here I use iframe to load image and video, I am in a single page

Solution 1:

So... that is actually really hard to read.. Only because I don't think you fully understand what your ajax is doing. Which in reality is confusing at first until you read everything and do it a couple of times...

So... data is going to be something like "NO VIDEO" and never be == lastData ... data is the RETURN from success...

However... we can have some fun with this.. You can start with a single ID..

<script>
  $(function(){
    var lastData = 0; // set your data to 0 as that is the real originalvalues(); // Go ahead and call the function on initialization so you can see it instantly.functionvalues(){
      lastData += 1// always increment by 1 if it is always one. You may need to fit this better for your situation.
      $.ajax({
        type: "POST", // You had GET url: "task.php",
        data: {ID: lastData}, // You did not have thissuccess: function(data){
          $('#myFrame').html(data);
          // if you have a better way to return lastData then do that here, but you will need to use json to get a better splitting of data.
        }
      });

   }
   setInterval(values, 5000);
  })(jQuery);
</script>

This should give you a better realization as to what is happening. You have to send data to actually read and then when you are in your PHP document you would use $_REQUEST['ID'] and do what you will with it.

Look up ajax and json encoding and get more familiar with the layout and how you should do this.

Honestly I wouldn't approach video / image slide show this way. I would use <img src="..."> and replace the source or do something very similar with the HTML5 <video> tag as it would handle most of my needs. I'm not sure if it will yours.

So yea.. Try something along those lines and hopefully it helps you..

This is by no means a full solution. I do not have a full project overview to get you to the final and the use of iframes does not make sense to me. I did not touch on that for a reason.

Post a Comment for "How To Manage Ajax Code To Display Image And Video Using Switch Case On Html"