2012-07-26 69 views
1

这是我的代码。这是用于使用json到jsoncall.php文件的传递值,并且需要获得响应。json响应不在IE中工作

var url = 'jsoncall.php'; 
    var calltype = "signin";  
    parameters = 'call='+calltype; 
    var email = document.getElementById('email').value; 
    var pass = document.getElementById('password').value; 
    var serverurl = document.getElementById('s_url').value; 
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; 

    if(email == "") { 
     alert("Plese enter your email address!"); 
     return false; 
    }else if(email != ""){ 

     if(reg.test(email) == false) {  
      alert('Invalid Email Address!'); 
      return false; 
     } 
    }else if(pass == "") { 
     alert('Please enter your password!'); 
     return false; 
    } 

    setTimeout(function() { 
     jQuery.getJSON(serverurl+url+'?callback=?', 
      {call:calltype, txtEmail: email, txtPassword: pass, login: ""}, 
       function(data) { 
        console.log(data); 
        //alert(data.result); 
        if(data.result == 0){      
         alert("Invalid email or password!"); 
         return false; 
        }else {       
         window.location = data.result; 
        } 

      }); 
     }, 100); 

这项工作在Crome,Firefox。但是这在IE中不起作用。当我按f12并在IE中获得开发者工具时,它开始在IE中工作。否则它将无法工作。感谢您的帮助。

+0

顺便说一句,'参数'变量在它之前没有'var' - 你正在泄漏一个全局变量。 – Inkbug 2012-07-26 05:05:57

回答

1

这是因为console.log仅在您启动开发人员工具后才可用。您可以使用try/catch块吸收错误,或创建一个虚拟console对象(如果它不存在)。

+0

非常感谢。我从我的代码中删除了console.log。现在它工作正常。非常感谢你。 – Madu 2012-07-26 05:01:47