0

The json response is in

{"userName":"clevermeal835","userRole":"Participant"}

I am getting alert message as success but while reading the response I am getting the error as

XMLHttpRequest cannot load the url Origin null is not allowed by Access-Control-Allow-Origin.

If i run the code from command prompt by --disable-web-security I am getting response
The below is code.

<html>  
<head>  
<meta charset="UTF-8">  
<script type="text/javascript" src="Scripts/jquery-1.4.2.min.js"></script>  
                     <script>  
        $(document).ready(  
        function() {  
        $("#jsonpbtn2").click(function() {  
            var uid = "clevermeal835";  
            var pwd = "Welcome_1";  
            var userType = "participant";  
            var surl="http://localhost:8080/RESTlet_WS/MobiSignIn/{\"userName\":\""+uid+"\",\"password\":\""+pwd+"\",\"userType\":\""+userType+"\"}/";  
                $.ajax({  
                    type : 'GET',  
                    contentType: "application/json; charset=utf-8",  
                    url : surl,  
                    dataType : 'json',  
                    headers : {Accept : "application/json","Access-Control-Allow-Origin" : "*"},  
                    crossDomain : true,  
                    success :SucceedFunc ,
                    error : function(data, textStatus, errorThrown) {
                            console.log("error"+' '+JSON.stringify(data) + ' ' + textStatus + '  ' + errorThrown);  
                    }
                    });  
                    function SucceedFunc(data) {
                        alert("success");
                        var userName = data.userName;
                        alert(userName);
                    }
                    });  
                });  
    </script>   
    </head>  
    <body>  
    <input id="jsonpbtn2" type="submit" value="button" />  
    </body>  
    </html>    
benomatis
  • 5,536
  • 7
  • 36
  • 59
paripurna
  • 135
  • 2
  • 10

1 Answers1

0

If you are calling, the html page ajaxCallPage.html in the question above, like file://.../ajaxCallPage.html then you are doing it wrong.

Put the ajaxCallPage.html file in your web server and call it like this http:/localhost:8080/.../ajaxCallPage.html. Then this error would not come up.

If thats the case, this question is a possible duplicate of XMLHttpRequest cannot load http://localhost:8080/exist/rest/db/.... Origin null is not allowed by Access-Control-Allow-Origin

Community
  • 1
  • 1
Sreenath S
  • 1,269
  • 1
  • 14
  • 21
  • In place of localhost I am placing ipaddress.If I remove how can i get the response from webserver and I have tried it too – paripurna Aug 21 '12 at 13:30
  • what is the url of the page you've pasted above in the question ? – Sreenath S Aug 21 '12 at 13:35
  • I'm asking this to verify if this is truly a cross-domain XmlHttpRequest. – Sreenath S Aug 21 '12 at 13:43
  • http://localhost:8080/RESTlet_WS/MobiSignIn/{\"userName\":\""+uid+"\",\"password\":\""+pwd+"\",\"userType\":\""+userType+"\"}/ this is the url i am using and uid = "clevermeal835" , pwd = "Welcome_1" ,userType = "participant"; – paripurna Aug 22 '12 at 04:25