Ajax call in Internet Explorer IE 7 & IE8 error


Ajax call in Internet Explorer IE 7 & IE8 error

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;
});  

上面的代码在chrome和firefox中运行良好,但在InternetExplorer7和8中不可用。

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

"对象不支持此属性或方法"

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

尝试添加

contentType: "application/json",

您可能还需要添加:

dataType: "json",

dataType: "text",

很难从你的例子中判断出到底返回了什么。。。

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

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

而不是用下面的行替换上面的行:

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