【问题标题】:AJAX Broswer issuesAJAX 浏览器问题
【发布时间】:2013-04-26 13:21:04
【问题描述】:

由于某种原因,我在让 AJAX 在不同的 Web 浏览器上正常工作时遇到了奇怪的问题。有什么特别需要的,或者有什么技巧可以让事情顺利进行吗?

我遇到的第一个问题是以下问题,它在 Chrome 中完美运行,但在 ie 和 firefox 中什么也没做:

function DeleteRideshare(pid){
    if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
    }
    else{// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }           
    // Verify
    var conf = confirm("Are you sure you want to delete this rideshare?");
    if(conf == true){
        xmlhttp.open("POST","updaterideshare.php",true);
        xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        xmlhttp.send("delete=true&PostID="+pid);    
        location.reload();                      
    }           
}   

我也有这个,它适用于 chrome 中的某些元素,而在 ie 和 firefox 中根本不适用:

$(document).ready(function(){
    $("#EditRideshareAjax").submit(function(){
        // Stop the from from submiting normally
        event.preventDefault();         

        // get the values from the elements on the page
        var values = $(this).serialize();

        $.ajax({
            type: "POST",
            url: "updaterideshare.php",
            data: values,
            success:     function(msg){                                         
                location.reload();
            },
            error:function(){
                alert("An error has occured, please try again");
            }
         });
    });
});

任何帮助或见解将不胜感激!谢谢!

【问题讨论】:

  • 这里到底是什么问题?
  • 当我在 firefox 和 ie 中提交 ajax 请求时什么都没有发生,但是如果有意义的话,当我使用 chrome 时工作完全正常
  • @user1875195:你检查过控制台请求是否有效吗?请求中未包含的某些逻辑可能有问题。
  • 具体如何检查?

标签: javascript jquery ajax cross-browser


【解决方案1】:

您不必在函数中将事件作为参数传递然后使用它。

           $("#EditRideshareAjax").submit(function(event){

【讨论】:

    猜你喜欢
    • 2013-06-01
    • 2012-06-24
    • 1970-01-01
    • 1970-01-01
    • 2015-03-02
    • 2012-05-10
    • 1970-01-01
    • 1970-01-01
    • 2016-03-14
    相关资源
    最近更新 更多