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)
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 ?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.