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.
asked Dec 25, 2013 at 2:35
user2898075
791 gold badge3 silver badges10 bronze badges
1 Answer 1
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);
});
Ahmed Siouani
13.9k12 gold badges63 silver badges73 bronze badges
answered Dec 25, 2013 at 2:38
xdazz
161k38 gold badges255 silver badges278 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
user2898075
Hmm, it's not replacing the div with the output from
input.php.xdazz
@user2898075 Of course you could do anything you want, the answer is just an example:)
default