0

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

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

2 Comments

Hmm, it's not replacing the div with the output from input.php.
@user2898075 Of course you could do anything you want, the answer is just an example:)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.