如何获得http响应? [英] How to get http response ?

查看:75
本文介绍了如何获得http响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个登录代码,返回json值。这段代码是用jquery编写的。当我点击登录按钮时,它没有给出任何回复。 jquery是:

Hi, I did a code to login which return json value. This code is written in jquery. When I click on login button, its not giving any response. The jquery is :

function loginEmail(par1, par2) {

            if (document.getElementById(par1).value == '') {
                alert('Please insert Email Address')
                return false;
            }
            if (document.getElementById(par2).value == '') {
                alert('Please insert Password')
                return false;
            }
            else {
                loader('lock');
                var query = 'aUserName=' + document.getElementById(par1).value + '&aPassword=' + document.getElementById(par2).value;

                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('POST', url);
                    httpRequest.send();
                }

                function alertContents() {
                    if (httpRequest.readyState === 4) {
                        if (httpRequest.status === 200) {
                        /*Control is not going in this if condition*/
                            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 {
                                    /*User is logged in*/
                                    checkCookie();
                                }
                            }
                            else {
                                var l = location;
                                window.location.href = '/[#This.Clean Url Full Path]';
                            }
                        }
                        else {
                            alert('There was a problem with the request.');
                        }
                    }
                }

                makeRequest('http://dev.livestuff.com/.LoginAsJSON?' + query);
            }
        }



我在这个if条件下遇到问题。该控件不在此....


I am getting problem in this if condition. The control is not going in this....

if (httpRequest.response) {
}



所以,如何解决这个问题。

谢谢


So, How to solve this problem.
Thanks

推荐答案

这篇关于如何获得http响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆