简体   繁体   中英

Want to load php file in div on page load

I am pretty new to ajax,jquery and javascript. So need help. I have a form. When submit button is clicked the div below the form displays the result from the php file. What i want is that it should display the php file into that div as soon as the main page loads and the div refreshes when submit button is pressed.

<script> 
   $(document).ready(function() { 
   $('#form1').ajaxForm(function() { 
   $('#blogup').val(''); // alert("Thank you for posting!"); 
   $("#display").load("showartposts.php")
   }); 
   }); 
</script> 

Here, display is the div to be displayed on page load and when the form is submitted it should refresh this div to display new posts from showartposts.php. It is just like a facebook wall post thing. j

you need to try this :

<script> 
   $(document).ready(function() { 
   $("#display").load("showartposts.php"); // call as soon as page load
   $('#form1').ajaxForm(function() { 
     $('#blogup').val(''); // alert("Thank you for posting!"); 
     $("#display").load("showartposts.php")
  }); 
  }); 
</script> 

You will need to submit the form using AJAX and then take the AJAX response (assuming its HTML) and replace the contents of the #display DIV.

Should be pretty trivial using jQuery.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM