I have a form that I need to post and show the result in a div. I'm not having any problems making the ajax call but I can't seem to figure out how to load the result to a div. I have tried:
$.ajax({
type: 'POST',
data: $('#someForm').serialize(),
url: '',
success: function(data) {
$('#someDiv').load(data);
}
});
but it does not seem to work properly. I'm nit sure if this should even work but the result is the the page i'm posting from being loaded into the div and not the url I'm posting to.
Any help would be great! Thanks!
I have a form that I need to post and show the result in a div. I'm not having any problems making the ajax call but I can't seem to figure out how to load the result to a div. I have tried:
$.ajax({
type: 'POST',
data: $('#someForm').serialize(),
url: 'http://somedomain./my/url',
success: function(data) {
$('#someDiv').load(data);
}
});
but it does not seem to work properly. I'm nit sure if this should even work but the result is the the page i'm posting from being loaded into the div and not the url I'm posting to.
Any help would be great! Thanks!
Share Improve this question asked Jun 11, 2010 at 16:16 mikemike 8,14119 gold badges55 silver badges68 bronze badges 2-
1
Have you verified that the data is successfully being returned? You could test in the
success
callback withconsole.log(data)
oralert(data)
. – user113716 Commented Jun 11, 2010 at 16:28 - Actually, I just figured out that there is a problem on the backend... Got it working with something else. Thanks ! – mike Commented Jun 11, 2010 at 16:44
1 Answer
Reset to default 11If the "result" is just HTML, then you'd say
$('#someDiv').html(data);
If you want it treated strictly as plain text:
$('#someDiv').text(data);