"jsonp"データ型を使用し、エラー関数呼び出しを使用してクロスドメインURLからjsonデータを取得するためにajax呼び出しを使用しています。私はmozillaの開発者 - >ネットワーク - >応答でjsonのデータを見ることができます。クロスドメインのjsonデータでコールバックが機能しない
{"datapoints": [{"record_timestamp": "10-09-2016 05:30","data": {"temperature": {"id": "3","param_name": "temperature","value": "28.6","unit": "celsius"}}}]}
JSONデータがjsonpcallbackにアップwrappigされていない
Error: callbackdata was not called
Stack trace:
[email protected]://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js:2:1821
b.converters["script json"]@http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js:4:16101
[email protected]://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js:4:7333
[email protected]://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js:4:10747
.send/[email protected]://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js:4:15393
[email protected]://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js:3:6392
n.event.add/[email protected]://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js:3:3202
CORS:25:7
SyntaxError: missing ; before statement
とmozillaのdaveloper-で応答>ネットワーク:次のエラーを取得
$(document).ready(function() {
$.ajax({
url : 'https://www.example.com /fetchdata?param=1',
type : 'POST',
crossDomain : true,
dataType : 'jsonp',
headers : {
'Access-Control-Allow-Origin' : '*',
'Access-Control-Allow-Methods' : 'POST'
},
jsonpCallback : 'callbackdata',
success : function(data) {
alert("success");
},
error : function(xhr, status, error) {
console.log(error);
alert("fail");
},
});
});
function callbackdata(response) {
alert(response)
}
:以下のコードです。解決策を見つけるのを手伝ってください。私が代わりに「JSONP」のデータ型として「JSON」とAJAX呼び出しを作るしようとした場合
、サーバは
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.example.com/fetchdata?param=1.(Reason: CORS header 'Access-Control-Allow-Origin' missing)
返信ありがとうございます。私はJSONとJSONPの違いを理解していますが、サードパーティのURLからデータ(json)が来たら、どうすればJSONPに変更し、どのようにJSONPをサポートすることができますか。助けてください。私はgoogleで何も得ていない。 – rahul
サードパーティのサーバがサポートしている必要があります。それがあればあなたの電話を認識します。このエラーが発生しないため、サードパーティがJSONP – trincot
okをサポートしていないことを意味します。我々はサーバがJSONPをサポートしていないとふりをしています。このシナリオで可能な代替案は何ですか。私に解決策を教えてください。 – rahul