Ricky Ahn
Ricky Ahn

Reputation: 191

XMLHttpRequest cannot load "THIS URL" Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin.

Im getting this error when trying to POST and XML from my company website to FRESHDESK API

here is the javascript

$(document).ready(function(){
  var data = 
  '<helpdesk_ticket>' +
    '<description>This is a test</description>' +
    '<email>[email protected]</email>' + 
  '</helpdesk_ticket>'
$.support.cors = true;
$.ajax({
    url: 'http://onehouse.freshdesk.com/helpdesk/tickets.xml',
    type: 'POST',
    crossDomain: true,
    data: data,
    dataType: "text",
    username: 'MY API CODE',
    password: 'X',

    success: function (result) {
        alert(result);
    },
  });

the full error is

XMLHttpRequest cannot load http://onehouse.freshdesk.com/helpdesk/tickets.xml. Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin. contacts?oid=00DU0000000I430&retURL=http%3A%2F%2Fwww.ironridge.com&email=ma…utes%5D%5Bdescription_html%5D=safsadfsdaf&00NU0000002xpYP=&submit=Submit:1

Does anyone have any solutions to this........it does not post the data to the FRESHDESK WEBSITE and i've been banging my heads for days now

Upvotes: 0

Views: 1828

Answers (2)

akonsu
akonsu

Reputation: 29536

This is a CORS feature (see http://en.wikipedia.org/wiki/Cross-origin_resource_sharing). Even though you set crossDomain to true in your request, the server that you post to has to support CORS for this to work. Namely, the server has to respond with specific HTTP headers for the browser to allow this request.

Upvotes: 0

Naftali
Naftali

Reputation: 146300

It says it right there in the error.

You cannot do any AJAX requests (aside from jsonp) to a different domain due to Access-Control-Allow-Origin.

Upvotes: 1

Related Questions