0

I have a big problem with RESTFul webservices.

Here is my architecture :

  • Server-side : I use EJB3 + RESTFul webservices.
  • Client-side : I use bootstrap twitter + JQuery 1.8 and Ajax methods to access my webservices.

I created a JSP on server-side to test my webservice before commiting it for client-side developpers. When I use this JSP all my webservices are working perfectly ! Then I try to access these webservices from an html page (remotely) and my $.ajax request doesn't work.

I rode a lot of posts about that, some people speaks about JSONP adding callback=? at the end of the URL or using dataType='jsonp'

The best I can do is seeing the object in my browser Resources but only error callback is called. I have an error like : ParserError : Error: jQuery18207595316471997648_1348928429983 was not called.

When I try to use dataType='text json' (as mentioned in some posts) nothing happens but the error callback is still called !

The thing is that when I just put the GET url directly in my web browser I can see the string of the corresponding JSON object, so it doesn't seems to come from my webservices.

here is an example of this JSON string :

{"member1":[{"email":"[email protected]","firstname":"Romain","idMember":"4","lastname":"Dev","login":"romain","password":"5026bc63b5418ffdb54f238db245ec01"},{"email":"[email protected]","firstname":"Product","idMember":"7","lastname":"Owner","login":"prodowner","password":"f5bf48aa40cad7891eb709fcf1fde128"}]} 

Here is an example of my ajax request :

$.ajax({
    url:'http://localhost:8080/myresource/all',
    type:'GET',     
    success: function(reponse) {        
        renderList(reponse);
    },  
    error:function (xhr, status, error){        
        alert('Error :'+xhr.responseText+' ('+status+' - '+error+')');  
    },  
    dataType: 'json'

  });

I use Glassfish server 3.1.2 and the only log I can see is :

INFO: Couldn't find JAX-B element for class javax.ws.rs.core.Response

But why would it work in my JSP and not in my HTML pages ??

I'm really stuck, I really need your help ! :)

Thank you very much in advance

0

1 Answer 1

1

You can try this function :

function sendRequest(success_callback,failure_callback,data,ws_url,asynchronous){
$.ajax({ 
    async: asynchronous,
    type: "GET",
    crossDomain: true,//if cross domain req 
    dataType: "json",
    Accept : "application/json",
    contentType: "application/json",
    url:"url",
    data:  data,
    success:success_callback,
    error: failure_callback
}); 

}

function success_callback(msg){

}

function failure_callback(msg){

}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.