jQuery发布错误

问题描述:

我通过jQuery将数据从表单发布到PHP页面。jQuery发布错误

以下是代码。让我知道你是否需要从php或html页面看到代码。

$("#createQuestionForm").submit(function(e) { 
    e.preventDefault(); 
    alert("check1"); 
    $.post("InsertNewQuestion.php", $("#createQuestionForm").serialize()).done(function(data) { 
     alert("check2"); 
    }); 
}); 

我可以看到第一个警报(“check1”),但问题是我看不到第二个警报(“check2”)。问题是什么?

------------------------------------------ AFTER EDIT-- -------------------------------------------------- ---------------------

我发现了这个问题:Uncaught TypeError:Object#has no method'done',how to fix this?

+2

当你调试时会发生什么?浏览器中是否有控制台错误?是否成功创建了“InsertNewQuestion.php”?对该请求的回应是什么? – David 2013-03-06 16:10:55

+0

我不认为在php文件中有任何问题,因为当我使用html文件将数据直接提交给没有JavaScript作为中间人的PHP时,没有错误。 – 2013-03-06 16:12:58

+0

检查浏览器工具的网络选项卡,返回什么? – jeroen 2013-03-06 16:16:35

我发现了这个问题。我的jQuery文件不是最新的。我更新了文件,它工作!

你为什么不re-read the $.post() documentation

$.post("InsertNewQuestion.php", $("#createQuestionForm").serialize(), function(data) { 
    alert("check2"); 
}, 'json'); 

更多关于你的文档网站上的观点和$.post()选项。

+0

我已经阅读了jQuery网站上的文档,那是我获得代码的地方。我无法使用他们提供的信息解决问题,这就是为什么我在这里发布了一个问题。 – 2013-03-06 16:16:34

+0

以我在这个答案中所写的方式使用它。此示例需要以下参数:url,data,success_callback,data_type-output。 – 2013-03-06 16:26:44

+0

唯一的区别是'json'。问题在于它刷新页面。如果我需要解析数据,我将只使用parseJSON。 – 2013-03-06 16:27:50