How to load images from a directory using javascript, ajax and php -


I'm new to stackworflow, I'm learning JavaScript and Ajax, I know how to open connection using Ajax But I have no idea how to use Ajax to load images from a specific directory in the same server. I have googled JavaScript and Ajax tutorials to load images by using javascript and any jQuery, lek Not I am unable to find any good tutorials because most of them using jQuery. I want to display images from a folder in an HTML div, is it possible to do without using jQuery?

It looked into the comments and I realized that I should edit the question. I would like to manually load multiple images into a folder without manually typing them into HTML. I'm able to manually use DOM to select files but I can display several images without replacing too many HTML code is required.

You do not really need to "load" the images.

You can make an Ajax request, which you want to get the source of the image (eg 'Image.png') and then insert an image into your HTML.

Here is a code sample:

  & lt; script type = "text / javascript" & gt; // Excerpt var xhr = New XMLHttpRequest (); // function when the AJAX request returns something back some xhr.onreadystatechange = function () (if (xhr.readyState == 4 & xhr.status == 200) returns something // // Returned Image Source var img_src = Xhr.responseText; // Insert an image into a div document.getElementById ('my_div') innerHTML = '& lt; img src = "' + img_src + '" />';}} // Open the desired page xhr .open ('POST', 'my_page.php', is true); // Ajax header xhr.setRequestHeader ('content-type', 'application / x-www-form-urlencoded'); // parameter xhr.send Send ('some_param =' + param_value); & lt; / script & gt;    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -