[英]Ajax Jquery call not working
我正在嘗試向以下URL發出簡單的ajax請求。 https://insightsoftwaresolutions.atlassian.net/rest/api/2/issue/createmeta?projectKeys=TES&issuetypeNames=Bug&expand=projects.issuetypes.fields
當我只是將URL放在瀏覽器導航欄上並按回車鍵時,它會收到JSON響應但是當我嘗試進行jquery ajax調用時它不起作用。 它沒有任何控制台錯誤。
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
<script>
$(document).ready(function () {
$.ajax({
cache: false,
type: 'GET',
crossDomain: true,
url: 'https://insightsoftwaresolutions.atlassian.net/rest/api/2/issue/createmeta?projectKeys=TES&issuetypeNames=Bug&expand=projects.issuetypes.fields',
contentType: 'application/json; charset=utf-8',
dataType: 'jsonp',
success: function (data) {
alert("success");
},
error: function (jqXHR, textStatus) {
//displayCallResults(jqXHR);
alert("error");
}
});
});
</script>
更新:
我將數據類型:'jsonp'更改為datatype:'json'。 然后我得到以下錯誤。
Origin http://localhost:3029 is not allowed by Access-Control-Allow-Origin.
您的服務器不支持JSONP 。 要么改變它
要么
在nginx添加標頭以支持服務器端的CORS。 或者您可以在服務器端添加CORS標頭。
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
完成后,您可以使用簡單的方法訪問代碼
$.getJSON(url).done(function(response) {
console.log(response); //here's your response
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.