简体   繁体   中英

refresh a div with as if it was a page refresh

Is it possible to reload a div as if it was a page refresh?

I have an jQuery submit my from and return only the raw data arrays as intended. There is no html being returned just arrays of data. How do I refresh the div 's html and php content, so it is populated with new data?

Here is what I've done so far to submit the form and return the data.

$(document).ready(function() {
    $("input:checkbox").change( function() {

var url = "index.php?action=resortFilter";

$.ajax({
       type: "POST",
       url: url,
       data: $("#locationFilter").serialize(), 
       success: function(data)
       {
           $(".resorts").html(data);
       }
     });
   })
});

It returns all the correct data except currently it just overwrites the div that contains all my html and php to display the data. Because the return is only data it effectively empties the div

The html and php page is structured like so

<div class="resorts">
    <?php foreach ( $results['data'] as $data ) { ?>
        <table></table> and so on..................
</div>

Now I cannot alter the file that actually handles the form and put in the html and php to return it. So I need to find a means of using the code already in the page itself

Two options either use ajax to call php that gets the array of data and returns it as html. Or you will have to use javascript to go through the array of data and convert it into usable html. You CANNOT get php code to run again on the client's computer, it is a server side language.

If you can't modify the code that the form is submitted to, can you create a new php file? You could send the ajax submission to it, then use Curl to submit the data to the actual form submission code get the response and convert it to html then return.

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