jQuery的阿贾克斯成功不被调用 [英] jQuery Ajax success not being invoked

查看:107
本文介绍了jQuery的阿贾克斯成功不被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的code,

$.ajax({
    type: "POST",
    url: action,
    data: params,
    success: function() {
        alert("Success");
    },
    error: function() {
        alert("error occurred");
    }  });

我在一个模式对话框形式,在提交我想留在对话框里面,而不是恢复到原来的窗口。我已经被周围的对话框的内容有一个div,然后调用#div.load(一些网页)的成功部分解决了其他地方这个问题。

I have a form inside a modal dialog window, on submission i would like to stay inside the dialog rather than return to original window. I have solved this issue elsewhere by surrounding the contents of the dialog with a div, and then calling #div.load("some page") in the success portion.

然而,由于某种原因,此页面上的成功,部分没有得到所有执行,虽然形式正确提交,该对话框关闭,并请求重新提交表单的操作URL。我试图发出请求的异步,但是这并没有帮助。

However, for some reason on this page the success portion does not get executed at all, although the form submits correctly, the dialog closes and the request is resubmitted to the action url of the form. I have tried to make the request asynchronous but that did not help.

我不明白为什么同样的code的另一个特点是工作没有在这里工作。 请让我知道,如果你有任何想法。

I cannot understand why the same code that works on another feature is not working here. Please let me know if you have any ideas.

谢谢, 娜塔莎

推荐答案

纯粹是猜测,因为没有code,足以说,但我要说的是,你的AJAX功能是由一个事件引发的那些通常的原因后的形式回服务器。尝试返回false在生成Ajax请求停止默认的事件处理动作的处理程序。

Purely a guess, because there's not code enough to tell, but I would say that your ajax function is being triggered by an event that would ordinarily cause the form to post back to the server. Try returning false in the handler that generates the ajax request to stop the default event handling action.

$('input[type=submit]').click( function() {
     $.ajax( ... );
     return false;
});

如果是这种情况,那么,AJAX调用正在取得,但成功的处理程序可被调用之前,页面卸载作为交背面结果

If this is the case, then the ajax call is being made, but before the success handler can be invoked, the page unloads as a result of the post back.

这篇关于jQuery的阿贾克斯成功不被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆