0

I'm using Jquery to try to grab some data from the Open Calais api, but if I cannot get a valid response. If I use data type "script" I get an error of "missing ; before statement. If I use data type "xml" or anything else I get a 403 error from the Open Calais server.

I decided to try the "script" data type based on the last entry on this Calais forum post

Please don't hold back on the critiques and comments regarding my code. I'm leaning as I go.

My code:

var baseUrl="http://api.opencalais.com/enlighten/calais.asmx/Enlighten";
var licenseID="wt8h3w3pt333eewdwsyuhut6";
var content="In response to a legislative provision in a bill reauthorizing the FAA, the agency has launched a comment period as it selects six test sites to evaluate unmanned aircraft systems. The focus of the proceeding will be determining the location of the test sites along with establishing...";
var PARMS="&contentType=text/xml&outputFormat=xml/rdf"
var PostDatavar = "?licenseID="+licenseID+"&content="+encodeURIComponent(content)+PARMS;
var componentURL=baseUrl+PostDatavar;

function sendIt(sendData){
$.ajax({
    url:componentURL,
    type: "POST",
    dataType:"script",
    success:function(data){
            alert(data)); 
            console.log(data);
    },
    error:function(){
    alert("it's broken");
    }}
);

}

iammatthew2
  • 639
  • 2
  • 7
  • 20

2 Answers2

1

this is because of the same origin policy. you cannot use simple ajax requests for cross domain requests. for more information see my answer for this question. you can learn more about how to overcome this issue by following this tutorial.

Community
  • 1
  • 1
Chamika Sandamal
  • 23,565
  • 5
  • 63
  • 86
0


Please use the following function as there were some syntax errors in the function that was written in the script posted above.

function sendIt(sendData){
$.ajax({
    url:componentURL,
    type: "POST",
    dataType:"script",
    success:function(data){
            alert(data); 
            console.log(data);
    },
    error:function(){
    alert("it's broken");
    }}
);
}
Akhilesh Sharma
  • 1,580
  • 1
  • 17
  • 29