Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh/reload the content in Div using jquery/ajax

I want to reload a div on click of a button. I do not want to reload the full page.

Here is my code:

HTML:

<div role="button" class="marginTop50 marginBottom">     <input type="button" id="getCameraSerialNumbers" value="Capture Again" class="disabled" />     <input type="button" id="confirmNext"  value="Confirm & Proceed" class="disabled marginLeft50" /> </div> 

On click of <input type="button" id="getCameraSerialNumbers" value="Capture Again"> Button a <div id="list">....</div> should reload without loading or refreshing full page.

Below is the Jquery which I tried, but not working:-

$("#getCameraSerialNumbers").click(function () {     $("#step1Content").load(); }); 

Please suggest.

Here is the DIV on my page, which contains Pictures and Serial numbers of some products... Which will be coming from database 1st time on the Page Load. But Is User faces some issue he'll click tthe "Capture Again" button "<input type="button" id="getCameraSerialNumbers" value="Capture Again">" which will load those information again.

The HTML Code of Div:-

<div id="step1Content" role="Step1ShowCameraCaptures" class="marginLeft">  <form>     <h1>Camera Configuration</h1>     <!-- Step 1.1 - Image Captures Confirmation-->     <div id="list">         <div>             <p>                 <a id="pickheadImageLightBox" data-lightbox="image-1" title="" href="">                     <img alt="" id="pickheadImage" src="" width="250" height="200" />                 </a>             </p>             <p>                 <strong>Pickhead Camera Serial No:</strong><br />                 <span id="pickheadImageDetails"></span>             </p>         </div>         <div>             <p>                 <a id="processingStationSideImageLightBox" data-lightbox="image-1" title="" href="">                     <img alt="" id="processingStationSideImage" src="" width="250" height="200" />                 </a>             </p>             <p>                 <strong>Processing Station Top Camera Serial No:</strong><br />                 <span id="processingStationSideImageDetails"></span>             </p>         </div>         <div>             <p>                 <a id="processingStationTopImageLightBox" data-lightbox="image-1" title="" href="">                     <img alt="" id="processingStationTopImage" src="" width="250" height="200" />                 </a>             </p>             <p>                 <strong>Processing Station Side Camera Serial No:</strong><br />                 <span id="processingStationTopImageDetails"></span>             </p>         </div>         <div>             <p>                 <a id="cardScanImageLightBox" data-lightbox="image-1" title="" href="">                     <img alt="" id="cardScanImage" src="" width="250" height="200" />                 </a>             </p>             <p>                 <strong>Card Scan Camera Serial No:</strong><br />                 <span id="cardScanImageDetails"></span>             </p>          </div>     </div>     <div class="clearall"></div>      <div class="marginTop50">         <p><input type="radio" name="radio1" id="optionYes" />Yes, the infomation captured is correct.</p>         <p><input type="radio" name="radio1" id="optionNo" />No, Please capture again.</p>     </div>     <div role="button" class="marginTop50 marginBottom">         <input type="button" id="getCameraSerialNumbers" value="Capture Again" class="disabled" />         <input type="button" id="confirmNext"  value="Confirm & Proceed" class="disabled marginLeft50" />     </div> </form> 

Now on click of <input type="button" id="getCameraSerialNumbers" value="Capture Again" class="disabled" /> button, the information which is in <div id="list">... </div> should be loaded again.

Please let me know if you need some more information.

like image 597
UID Avatar asked Aug 28 '13 13:08

UID


People also ask

Can we refresh the div using jQuery?

jquery reload div after every N secondsScheduling div content to refresh its content can be done by using the setInterval method. setInterval function helps to execute a specified function or piece of code at given intervals. Here the interval is in milliseconds.

How do I reload a div without reloading the whole page?

Use this. $('#mydiv'). load(document. URL + ' #mydiv');


1 Answers

$("#mydiv").load(location.href + " #mydiv"); 

Always take note of the space just before the second # sign, otherwise the above code will return the whole page nested inside you intended DIV. Always put space.

like image 86
Peca Avatar answered Oct 01 '22 09:10

Peca