最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin8PV0评论

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);

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far