本文介绍了如何解决跨域问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 您好,我已经设计了一个窗口表单应用程序,我在其中调用了一个jQuery。脚本正在关注 < script 类型 = text / javascript > var 电子邮件; var pwd; function loginuser(email,pwd){ var query = ' aUserName =' + email + ' & aPassword =' + pwd; 函数makeRequest(url){ if (window.XMLHttpRequest){ httpRequest = new XMLHttpRequest(); } else if (window.ActiveXObject){ 尝试 { httpRequest = new ActiveXObject( Msxml2.XMLHTTP); } catch (e){ try { httpRequest = new ActiveXObject( Microsoft.XMLHTTP ); } catch (e){} } } if (!httpRequest){ alert(' 放弃:(无法创建XMLHTTP实例'); return false ; } httpRequest.onreadystatechange = alertContents; httpRequest.open(' GET',url); httpRequest.send(); } function alertContents(){ if (httpRequest.readyState === 4 ){ if (httpRequest.status === 200 ){ alert(httpRequest.status); // httpRequest.open(GET,window.location.href,false); // httpRequest.responseType =document; // httpRequest.send(); if (httpRequest.response){ var info = JSON.parse(httpRequest.response); if (info.Error){ alert( 此次请求无法完成。请稍后再试。); loader( unlock); } else { checkCookie(); } } else { console.log( 忽略空值); alert( 此次请求无法完成。请稍后再试。); } } 其他 { alert('' 请求有问题。'); } } } makeRequest(' http://dev.livestuff.com/.LoginAsJSON?' +查询); } < / script > 控件不在if内(httpRequeset.Response)条件,当我通过警报打印它时,它显示未定义的警报。这可能是跨领域的问题,但我不能正确理解。所以我必须为此做些什么我必须改变。 谢谢。解决方案 Hello, I have design a window form application, in which I call a jQuery. The script is following<script type="text/javascript"> var email; var pwd; function loginuser(email, pwd) { var query = 'aUserName=' + email + '&aPassword=' + pwd; function makeRequest(url) { if (window.XMLHttpRequest) { httpRequest = new XMLHttpRequest(); } else if (window.ActiveXObject) { try { httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { } } } if (!httpRequest) { alert('Giving up :( Cannot create an XMLHTTP instance'); return false; } httpRequest.onreadystatechange = alertContents; httpRequest.open('GET', url); httpRequest.send(); } function alertContents() { if (httpRequest.readyState === 4) { if (httpRequest.status === 200) { alert(httpRequest.status); //httpRequest.open("GET", window.location.href, false); //httpRequest.responseType = "document"; // httpRequest.send(); if (httpRequest.response) { var info = JSON.parse(httpRequest.response); if (info.Error) { alert("Request cannot be completed this time. Please try again later."); loader("unlock"); } else { checkCookie(); } } else { console.log("ignoring null value"); alert("Request cannot be completed this time. Please try again later."); } } else { alert('There was a problem with the request.'); } } } makeRequest('http://dev.livestuff.com/.LoginAsJSON?' + query); } </script>The control is not going inside the if(httpRequeset.Response) condition and when I print it through alert, it showing undefined alert. It may be the problem of cross domain but I am not understanding properly. So what I have to do for this where I have to change.Thanks. 解决方案 这篇关于如何解决跨域问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-09 23:01