【问题标题】:Ajax call in Internet Explorer IE 7 & IE8 errorInternet Explorer IE 7 和 IE8 错误中的 Ajax 调用
【发布时间】:2012-03-01 11:27:27
【问题描述】:

我在 javascript 文件中的代码:

$("#login").click(function(){


    username=$("#user_name").val();
    password=$("#password").val();
     $.ajax({
        type: "POST",
        url: "login.php",
        data: "username="+username+"&password="+password,
        success: function(value)
        {
           //code


        },
        beforeSend:function()
        {
             $("#add_err").html("Loading...")
        }
    });
     return false;
});  

aboue 代码在 chrome 和 firefox 中运行良好,但在 Internet Explorer 7 和 8 中无法运行。

当我尝试在 Internet Explorer 7 中访问该页面时,它显示以下错误消息:

“对象不支持此属性或方法”

请给我一个解决方案,如何在 IE7 中克服这个问题

【问题讨论】:

  • 我假设在您的 success 函数中您有 //code 您只是输入错误并遗漏了 if 语句?否则这可能是您的问题。
  • 除非if{.. 丢失,否则看起来没问题,如果您想要诊断,您不能用真实代码代替//code
  • 顺便说一句,如果你还没有这样做的话,你真的应该使用 var 关键字声明 yoru 变量。例如var username=$("#user_name").val();
  • 看起来不错。您是否有行号或它在抱怨哪个对象?
  • 这行显示错误:$.ajax({ Where there is a ajax call

标签: php javascript jquery ajax internet-explorer


【解决方案1】:

尝试添加

contentType: "application/json",

您可能还需要添加:

dataType: "json",

dataType: "text",

很难从你的例子中确切地知道返回了什么......

【讨论】:

    【解决方案2】:

    我在我的代码中做了以下更改:

     username=$("#user_name").val();
      password=$("#password").val();
    

    而不是上面的那些行替换为以下几行:

    var username=$("#user_name").val();
      var password=$("#password").val();
    

    【讨论】:

      猜你喜欢
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-22
      • 1970-01-01
      • 2011-05-01
      相关资源
      最近更新 更多