thank_you
thank_you

Reputation: 11107

Simple AJAX POST return HTML

I am using $.post to post some data into the server and if that php file works then I am returned with some html snippet. Now the problem lies within the $.post code. I can't insert the returned data from the php file onto the original file that contains the $.post code. Firebug shows that the html snippet does return back but I'm seeing it on my screen. What's the problem?

Here is the code below for the file containing the .post()

<script type="text/javascript" >

$.post('ajax_send_band_request.php', {

user_id : user_id,
band_request: band_request,
where_to_go: where_to_go,
when_start: when_start,
when_end: when_end,
time: time  

}, function(data){

$(data).find('#message_return').appendTo("#response_from_request_verification")

})  

});

</script>           

<div id="response_from_request_verification"></div>

Here is the summarized php file version.

if(this_function_sends the data to the server($register_data) === true);

{

?>

<div id="message_return">Request sent!!</div>

<?php

} else

{

?>  

<div id="message_return">Request was not sent!</div>    

<?php   

}

?>

Upvotes: 0

Views: 339

Answers (3)

Sad Al Abdullah
Sad Al Abdullah

Reputation: 379

try this : $('response_from_request_verification').html(data);
or $('response_from_request_verification').appendTo(data);

Upvotes: 0

Ben Stephens
Ben Stephens

Reputation: 563

The only thing I can see wrong here is the missing ; on the appendTo line.

Make sure you have that on your actual code, and then all I can suggest is running through it with an interactive debugger like firebug.

Set a breakpoint on the appendTo line, use the console to make sure $(data).find('#message_return') is getting the peice you want etc

Upvotes: 0

Musa
Musa

Reputation: 97672

Remove the .find() part, you already have the div#message_return with $(data). .find() doesn't check the root element for a match, just descendants.

$(data).appendTo("#response_from_request_verification")

Upvotes: 4

Related Questions