繁体   English   中英

Ajax Jquery调用不起作用

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM