Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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 :
JavaScript
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);
            }
        }

I am getting problem in this if condition. The control is not going in this....
JavaScript
if (httpRequest.response) {
}

So, How to solve this problem.
Thanks
Posted
Updated 13-Apr-14 21:17pm
v2
Comments
Sampath Lokuge 14-Apr-14 4:49am    
Check whether are there any errors on js file by using chrome dev tools ?
Priyanka Bhawsar 14-Apr-14 5:45am    
No, there is no any error, its giving undefined in response.
Sunasara Imdadhusen 15-Apr-14 5:27am    
What will be the response from web services "http://dev.livestuff.com/.LoginAsJSON?" you can check on postman (Google Chrome Plugin) using same URL and Parameter.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900