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 

Salesforce Ajax call throwing exception

I have the following ajax call that I am sending to an outside domain. but it straights goes to error function is there something that I am missing . I have added the url into remote setting
             type: "POST",
             url: '',
             headers: {"Accept" : "application/json",
                        "Content-Type": "application/json" },
             data: JSON.stringify(address),
             crossDomain : true,
             dataType: 'json',
             success: function (responseData) {

            error: function (request, status, 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");

the error "Sorry, Something in the system has gone wrong , Please try again Later" but in console I also get this. I am not sure if there anything script cdn i need to include or if the format is wrong. any hint is really appriciated 

<message collected>
 <message collected>
karthikeyan perumalkarthikeyan perumal

You're being blocked by the browser "Same origin policy". That is, you cannot do ajax requests to other than the same domain that the script was loaded from. There are, however, some workarounds:

Use JSONP. This is probably the most cross browser compatible solution

Configure your application to support CORS. This works in most modern browsers, but not in some older.

Create a proxy service on your own server. That is, mount an endpoint, e.g. /externalService that proxies the request on the server side to the remote endpoint. It also will work in all browsers, but will involve more work on the server side.

kinldy Refer the Below URL for Same Issue,

Hope this will help you.

Mark Best ANSWER if its works for you

Behzad Bahadori 18Behzad Bahadori 18
@karthik, all its doing right now its refreshing the page. it doesnt really give me XMLHttpRequest error. I am not sure still what I need to change, in that example the guy is doing samething at the end . how is this different than what i am doing?
var fbURL="";

    url: fbURL+"&callback=?",
    data: "message="+commentdata,
    type: 'POST',
    success: function (resp) {
    error: function(e) {
        alert('Error: '+e);