0

晚上好,

我用不同的语法尝试了很长时间,但没有成功:一切都在 PhoneGap 上运行。我得到了console_logbefore $.ajax..,但之后没有任何错误或输出。单击“提交”后,将执行此 JS 代码:

 console.log(in_mail + " " + in_text);
        $.ajax({
            type: 'POST',
            data: "mail="+in_mail+'&text='+in_text,
            url: 'http://example.com/comment.php',
            success: function(data){
                console.log(data);
                alert('Your comment was successfully added');
            },
            error: function(){
                console.log(data);
                alert('There was an error adding your comment');
            }
        });
 console.log("POST done");  
4

1 回答 1

0

Two things:

  1. If you are executing this script via submit button you should consider returning true on success and false on error.
  2. Your "POST DONE" would execute before the success or error functions would be invoked because post is asynchronous.

I have reproduced the example with jsFiddle you can find it here http://jsfiddle.net/jUBMN/

于 2012-06-30T22:09:11.890 回答