简体   繁体   中英

Use javascript to send post request

I'm currently using javascript to send a post request to a PHP file on my server:

function insertComment(id, status) {
   $.post("http://test.com/includes/insert.php",{id:id, status:status});
}

However, how can I edit my code so that when the post request is sent and when insert.php is loaded, the code loads the output from insert.php in a DIV on the original page that called the insertComment() function.

Your php side should output some result, and your javascript side should take the result and do something.

Example:

$.post("http://test.com/includes/insert.php",{id:id, status:status}, function(data) {
    $('#your_div').html(data);
});

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