2012-03-10 12 views
0

Open Calais apiからデータを取得しようとしていますが、有効な応答が得られない場合はJqueryを使用しています。データ型 "script"を使用すると、 "missing; before statement"というエラーが発生します。データ型 "xml"などを使用するとOpen Calaisサーバーから403エラーが発生します。JqueryのAjaxコールでデータ型の問題が発生しました

私はこのCalais forum post

上の最後のエントリに基づいて「スクリプト」データ型は、私のコードについての批判やコメントに我慢しないでください、私が行くように、私が傾いてる

私のコード:。。

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"); 
    }} 
); 

}

答えて

0


上記のスクリプトに記述されている関数に構文エラーがありますので、以下の関数を使用してください。

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

投稿したコードは私のものと同じです。何か不足していますか? – iammatthew2

+0

はい、使用される中括弧の開閉に問題がありました。 –

1

これは、同じ発信元ポリシーのためです。クロスドメイン要求に対して単純なajaxリクエストを使用することはできません。詳細はthis questionの私の答えを見てください。この問題を解決する方法の詳細については、this tutorialをご覧ください。

+0

もちろん!それを指摘してくれてありがとう。私はPHPを介してそれを実行し、ここに投稿します。 – iammatthew2

関連する問題