Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Highlighted
Contributor
Posts: 19
Registered: ‎04-05-2011
My Device: Storm2 9550
My Carrier: Software Developer

Error while post the parameter with XMLHttp post method to RESTFul web service method with RESTEasy framework

 

This is server side code:
@Path("/json/searchEmployee/{empno}")
 @POST
    @GET   // this method process GET request from client
    @Consumes("'application/x-www-form-urlencoded")
    @Produces("application/json")   // sends JSON
    public String getJson( @PathParam("empno") int empno) {  // empno represents the empno sent from client   
      switch(empno) {
          case 1 :
              return "{'name':'George Koch', 'age':58}";
          case 2:
              return "{'name':'Peter Norton', 'age':50}";
          default:
              return "{'name':'unknown', 'age':-1}";
      } // end of switch
   }

 

 

 

 

I used to make a call fomm blackcerry widget application with following code in javascript:

 

 

var xmlHttp = new XMLHttpRequest();

var params = "empno=1";

    

function doClick() {

  var url = "http://localhost:8080/UE-WS/v1/search/json/searchEventz";

  xmlHttp.open('POST', url, true);

  alert("opening url");

  xmlHttp.setRequestHeader('Content-Type', 'application/JSON');

  xmlHttp.setRequestHeader('Content-length', params.length);

  xmlHttp.setRequestHeader('Connection', 'close');

  xmlHttp.onreadystatechange = callbackFunction;

  document.getElementById('searchresult').innerHTML = "Requesting...";

  xmlHttp.send(params);

}

    

function callbackFunction(){

 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

     { 

     if (xmlHttp.status != 200)

        {

        alert('BadStatus');

        return;

        }

     }

  var result = xmlHttp.responseText;  

   var searche = JSON.parse(result);

   alert(searche.name);

   alert(searche.age);

}

 

 

 

Above code is given following error...

 

SyntaxError: Error in eval(): Unexpected ')'..

()
 Running  at line  468: j=eval("("+text+")");.
 Called from line   28: var searche=JSON.parse(result);.

SyntaxError: Error in eval(): Unexpected ')'..()
Running  at line  468: j=eval("("+text+")");. Called from line   28: var searche=JSON.parse(result);.

 

 

 

 

Is there any problem in code , could any one can tell me how to post the json object with AJAX post method to RESTFul web service method with RESTEasy framework.

 please answer dis as early as possible.

 

Thanks