【发布时间】:2023-03-03 04:16:02
【问题描述】:
我不确定为什么 jQuery 表单插件成功回调函数没有执行。为什么回调没有执行,如何执行回调?
代码:
<script type="text/javascript">
$(document).ready(function() {
var insertOptions =
{
// other available options:
url: 'manage_livestock/insert_livestock',
type: 'post',
dataType: 'json',
clearForm: true,
//resetForm: true
// $.ajax options can be used here too, for example:
timeout: 3000,
success: showResponse
};
$("#livestock").ajaxForm(insertOptions);
});
function showResponse(responseText, statusText, xhr, $form)
{
alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
'\n\nSuccess!');
}
</script>
-丰富的
【问题讨论】:
-
你确定返回的是
200http代码吗? -
您是否尝试在 firefox 中使用 firebug 加载页面?也许 zerkms 是对的,而您没有获得 200 ok 状态。
-
@zerkms @Elad Lachmi 我收到 200 ok 状态,我在 firebug 中验证了它。状态为 200 ok 的页面返回:Values has been inserted successfully!
-
@dottedquad: 响应是有效的 json 吗?
-
我将数据类型更改为 html。现在它起作用了。我将不得不等待 8 小时才能回答我自己的问题。
标签: jquery forms jquery-plugins