0

I wanted to create a little web page which ask this server (http://resumemanagerrestserver.juanwolf.cloudbees.net/) and use the XML received.

But the problem is when I do :

var resumes;
jQuery.ajax({
    type: "GET",
    url: "http://resumemanagerrestserver.juanwolf.cloudbees.net/?callback=?",
    contentType: "text/plain; charset=utf-8 ",
    dataType: "xml",
    success: function (data, status, jqXHR) {
        resumes = data;
    },
    error: function (jqXHR, status) {
        // error handler
    }
});

I have this response : ML Parsing Error: no element found Location: moz-nullprincipal:{2041758e-b063-4f84-898d-2ff62d487a5d} Line Number 1, Column 1:

I tried a GET request with Advanced REST client, it works.

If someone has a solution i will appreciate (and love him for the REST of my life)

Edit

I changed the old code by :

function getResumes() {
    var resumes;
    var url = 'http://resumemanagerrestserver.juanwolf.cloudbees.net/?callback=?';

    var xhr = createCORSRequest('GET', url);
    xhr.onreadystatechange = function() {if (xhr.readyState==4) alert("It worked!");};
    xhr.setRequestHeader("Content-type", "application/xml");
    xhr.setRequestHeader("Connection", "close");
    if (!xhr) {
      alert('CORS not supported');
      return;
    }

    // Response handlers.
    xhr.onload = function() {
      resumes = xhr.responseText;
      alert('Response from CORS request to ' + url + ': ' + resumes);
    };

    xhr.onerror = function() {
      $('#errorPopupLink').get(0).click();
    };

    xhr.send();
    return resumes;

}

Now, the request isn't red in Firebug, but I still have this

 XML Parsing Error: no element found Location: moz-nullprincipal:{d9ee4013-542d-4f65-a310-e1719d99bcae} Line Number 1, Column 1

Someone has a solution ?

Juanwolf
  • 840
  • 9
  • 19
  • I'm getting same-origin errors, so you probably can't do that. – adeneo Apr 12 '14 at 13:26
  • That seems to imply that no data is being returned or that the data is invalid. Check in the "Network" tab of the developer console (F12 -> Network in Chrome) and look for the AJAX call. You can look at the response or any errors from there. – Sumner Evans Apr 12 '14 at 13:28
  • 2
    As adeneo wrote you may have a problem with same origin policy. Please test if it works if you place the calling page and script on the same domain http://resumemanagerrestserver.juanwolf.cloudbees.net. See also: [ways to circumvent the same-origin policy](http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy) – lefloh Apr 12 '14 at 14:01
  • I tried it on localhost with Tomcat. It doesn't work, I have the same error. And my server send an Access-Control-Allow-Origin: *, so normally i can access to it ? Am I right ? – Juanwolf Apr 12 '14 at 14:48
  • Which Server sends the Access-Control-Allow-Origin Header? The server providing the script or the server providing the ajax-requested data? – lefloh Apr 12 '14 at 16:55
  • The server providing the ajax-requested data – Juanwolf Apr 12 '14 at 16:59
  • 1
    That may be the problem. I thought the first page tells the browser that AJAX-Requests may leave the domain. – lefloh Apr 12 '14 at 17:02
  • 1
    I found the solution. I feel a little bit ashamed but well now it works. I forgot to add the header in the server side for the GET Request, I put it just for PUT request... – Juanwolf Apr 12 '14 at 17:19
  • 1
    you should offer an explanation of what fixed your problem as an answer so that others can learn. :) – J.Wells Apr 15 '14 at 02:14

1 Answers1

0

The answer at my question was simple. The problem comes from the server. The code client in the Edit part was right.

The server here (http://resumemanagerrestserver.juanwolf.cloudbees.net/) is a JEE server using Spring. The fact is if you don't allow externals clients to use your own resources (see http://en.wikipedia.org/wiki/Cross-origin_resource_sharing), they will be blocked. So I just add CORS headers to get* functions, and it works well now.

If you are searching for how to create CORS headers with spring, this post can help you : http://zhentao-li.blogspot.fr/2012/06/enable-cors-support-in-rest-services.html

Juanwolf
  • 840
  • 9
  • 19