Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SyntaxError: invalid label while retrieving JSON object

When retrieving JSON object I receive the following error:

  1. SyntaxError: invalid label in Mozilla.
  2. Uncaught SyntaxError: Unexpected token : in Chrome

My JSON object is the format shown below:

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

Code:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="Scripts/jquery-min.js"></script>
<script src="Scripts/jquery_validate.js"></script>
<script>
$(document).ready(function() {
    loadLatestTweet();  
});

function loadLatestTweet(){
var xhr = new XMLHttpRequest();
var uid = "clevermeal835";
var pwd = "Welcome_1";
var userType = "participant";
    var surl =      'http://localhost:8080/RESTlet_WS/MobiSignIn/{"userName":"'+uid+'","password":"'+pwd+ '","userType":"'+userType+'"}&callback=?';

    var jqxhr = $.getJSON(surl, function() {
        alert("success");
    }).success(function() { alert("second success");   }).error(function() { alert("error"); }).complete(function() { alert("complete"); });
    jqxhr.complete(function(){ alert("second complete"); });
 }
 </script>
</head>
<body>
<input id="jsonpbtn2" type="submit" value="button" />
</body>
</html>
like image 528
paripurna Avatar asked Aug 09 '12 11:08

paripurna


1 Answers

you can make code seem like this

var params = { "Username": UserNameValue,"Password": PassValue};


        $.ajax({
            type: "POST",
            url: "http://localhost:8080/RESTlet_WS/MobiSignIn/",
            contentType: 'application/json',

            data: JSON.stringify(params),
            dataType: 'json',
            async: false,
            cache: false,
            success: function (response) {


            },
            error: function (ErrorResponse) {


            }
like image 145
Jignesh.Raj Avatar answered Oct 22 '22 04:10

Jignesh.Raj