最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jquery, ajax, load post result to div - Stack Overflow

programmeradmin9浏览0评论

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 with console.log(data) or alert(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
Add a ment  | 

1 Answer 1

Reset to default 11

If the "result" is just HTML, then you'd say

$('#someDiv').html(data);

If you want it treated strictly as plain text:

$('#someDiv').text(data);

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论