function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Behzad Bahadori 18Behzad Bahadori 18 

jquery.ajax in Visualforce

I don't konw whether there are some error in my code, so does anyone have experiences about use jquery.ajax in Visualforce or how to post a request to an external service in Visualforce?
When this code execute, I receieve the response with error method: textStatus : error XMLHttpRequest.readyState : 0 XMLHttpRequest.status : 0
 
$.ajax({
     type: "POST",
     url: 'https://www.me.com/qualification', // outside Domain
     headers: {"Accept" : "application/json",
                "Content-Type": "application/json" },
     data: JSON.stringify(address),
     crossDomain : true,
     dataType: 'json',
     success: function (responseData) {
        console.log(responseData);
    getAddresses();

    },
    error: function (request, status, error) {
        console.log(request.responseText);
        console.log(status);
        console.log(error);
        var result = $("#selections").append("Sorry, Something in the system has gone wrong , Please try again Later");
        console.log("Sorry, Something in the system has gone wrong , Please try again Later");
    }

});

 
Pankaj MehraPankaj Mehra

Hi

I tried your request and I am getting below error: 
 
Javascript returned an HTTP 0 error. One common reason this might happen is that you requested a cross-domain resource from a server that did not include the appropriate CORS headers in the response.

Try opening developer console to see error something like this 
 
uz.js:1 Uncaught DOMException: Blocked a frame with origin "http://fiddle.jshell.net" from accessing a cross-origin frame.(…)document.onmousemove @ uz.js:1
uz.js:1 Uncaught DOMException: Blocked a frame with origin "http://fiddle.jshell.net" from accessing a cross-origin frame.(…)document.onmousemove @ uz.js:1
Either your rest service is not proper or the brower is restricting the service giving cross-origin frame error.

Thanks


If you're satisfied with the answers provided, please don't forget to select a Best Answer.