简体   繁体   English

Ajax调用可在IE和Chrome中运行(并且仅在Firefox中,当在ajax调用结束时以调试模式添加断点时)

[英]Ajax call works in IE and Chrome (and only in Firefox when adding breakpoint in debug mode at end of ajax call)

I currently have the following code that works in IE and Chrome. 我目前有以下在IE和Chrome中运行的代码。 The following issue is only within Firefox (which weirdly enough I can make it work in Firefox when in Debug mode and I add a breakpoint at the end of the ajax call shown in comments below). 以下问题仅在Firefox中存在(很奇怪,在调试模式下,我可以使它在Firefox中运行,并在下面的注释所示的ajax调用的末尾添加一个断点)。 I believe it might have something to do with the ajax call below (where it errors). 我相信这可能与下面的ajax调用有关(错误)。 (SEE CODE COMMENTS FOR DETAILS). (有关详细信息,请参见代码注释)。

I have the following code that receives the data from the forms and sends it to another JavaScript function to send the data back to MVC controller function that adds a user into a database. 我有以下代码,这些代码从表单接收数据并将其发送到另一个JavaScript函数,以将数据发送回MVC控制器函数,后者将用户添加到数据库中。

$('#addUserSubmit').click(function () {
    var tagId = $(this).closest('form').find('input[name="userTag"]').val();
    var adminUser = $(this).closest('form').find('input[name="userName"]').val();
    AddUser(tagId, adminUser);
});

function AddUser(tagId, adminUser) {
    var data = JSON.stringify({
        'tagId': tagId,
        'adminUser': adminUser
    });
    $.ajax({ //HERE IS WHERE THE ERROR OCCURS (After it goes through to set all of the variables below).
        type: "POST",
        url: "/UsersAccounts/AddUser",
        data: data,
        success: function (outVal) {
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest + textStatus + errorThrown);
        },
        contentType: 'application/json'
    }); //IF I ADD A BREAKPOINT HERE IT WILL WORK IN GOING TO THE MVC 
        //FUNCTION TO BELOW AND IT WILL WORK AS INTENDED (BUT IF I RUN 
        //THE CODE NORMALLY OR WITHOUT A BREAKPOINT HERE IT WILL ALERT 
        //WITH THE ERROR ABOVE).
}

    [HttpPost]
    public String AddUser(int tagId, string adminUser){
        if (tagId > 0){
            try{
                using (TubeBPC db = new TubeBPC()){
                    Users user = new Users() {TAGID=tagId, AdminUser=adminUser };
                    db.Users.Add(user);
                    db.SaveChanges();
                    return "success";
                }
            }
            catch(Exception dbe){
                throw dbe;
            }
        }
        else{
            throw new ArgumentOutOfRangeException("TagID is not a positive number");
        }
     }

Any help is much appreciated! 任何帮助深表感谢!

I managed to do more research and found this answer to be the solution. 我设法进行了更多研究,并找到了解决方案。

"In order to wrap this code in a function the returns a boolean and does not require a callback function (a blocking procedure) you will need to use a synchronous request" “为了将此代码包装在一个函数中,它返回一个布尔值并且不需要回调函数(阻塞过程),您将需要使用同步请求”

jquery ajax dont work without firebug break point 没有firebug断点,jQuery ajax无法正常工作

Hope it helps someone else! 希望它能帮助别人!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jquery $ .ajax调用在Chrome或Firefox中导致401未经授权的响应,但在IE中有效 - jquery $.ajax call results in 401 unauthorized response when in Chrome or Firefox, but works in IE Firefox上的chrome上的ajax呼叫下载失败 - ajax call download fails on chrome works on firefox 加载div进行AJAX调用不会在IE或Chrome中显示,在Firefox中可以正常工作 - Loading div for AJAX call doesn't display in IE or Chrome, works fine in Firefox 在chrome / safari中的文件下载过程中,$ ajax呼叫正处于挂起状态 - $ajax call is pending during download file at chrome/safari not in IE/firefox jQuery AJAX调用在Firefox中有效,但在IE中无效-返回有效响应 - jQuery AJAX call works in Firefox but not IE - valid response returned Ajax 调用/javascript - 在 IE、Firefox 和 Safari 上运行良好,但在 Chrome 上运行不正常 - Ajax call/javascript - working fine on IE, Firefox and Safari but not on Chrome 在Ajax调用成功后复制到剪贴板,可在Chrome中使用,但在Firefox中无法使用 - Copy to clipboard after success in ajax call, works in Chrome but not in Firefox ajax调用在Safari和Firefox上失败,没有任何错误,但可在Chrome上运行 - ajax call fails on Safari and Firefox without any errors but works on Chrome AJAX呼叫可在Chrome中使用,但不能在IE中使用 - AJAX call working in Chrome but not IE Ajax 调用在 chrome/safari 中有效,但在 ff 和 ie 中失败 - Ajax call works in chrome/safari but fails in ff and ie
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM