PhoneGap jQuery POST不起作用


PhoneGap jQuery POST not working

晚上好,

我尝试了很长时间使用不同的语法,但没有让它工作:一切都在PhoneGap上运行。我在$.ajax..之前得到console_log,但在之后没有任何错误或输出。单击"提交"后,将执行此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");  

两件事:

  1. 如果您通过提交按钮执行此脚本,则应考虑在成功时返回 true,在错误时返回 false。
  2. 您的"POST DONE"将在调用成功或错误函数之前执行,因为 post 是异步的。

我已经用jsFiddle重现了这个例子,你可以在这里找到它 http://jsfiddle.net/jUBMN/