tags:

views:

35

answers:

1

Hello, I tried sending some data like so:

<form action="http://www.someurl.com/something.php" id="login">
    <input type="textbox" id="UserName" value="user">
    <input type="textbox" id="Password" value="password">
    <input type="submit" value="submit">
</form>
<div id="result"></div>
<script type="text/javascript">


            $('form#login').submit(function() {
               $.post($('form#login').attr('action'), $('form#login').serialize(), function(data) {
                   $('#result').html(data+'222')
               });
               return false;
            });



</script>

Now, the value of #result div change to 222... that is: the post was successful but for some reason there is no data, and when I go directly to something.php and post manually, it does bring back data (am I mistaken or does the post(success(data)) variable returns the whole page returned after you post something? if so, how could it be?)

Thank you very much for your help

A: 

what is your request type?

Try this...


$('form#login').submit(function() {
               $.post($('form#login').attr('action'), $('form#login').serialize(), function(data) {
                   $('#result').html(data.success+'222')
               });
               return false;
            },'json');

Have your script out put this as a test: {"success" : "some data" }

mike clagg
oh I realized that the page is getting another call for GET and has a check for headers so I can't get the data from outside the server...any ideas about that? some sort of simulation ?
Asaf
Not sure I understand your question. As far as a simulation just create a php script called fortest.php, and have it say this:{ "success" : "this worked!" }I have written a bit here on creating standardized output for jQuery ajax here:http://geektasking.com/?p=50
mike clagg