简体   繁体   English

Ajax Jquery调用不起作用

[英]Ajax Jquery call not working

i'm trying to make a simple ajax request to the following URL. 我正在尝试向以下URL发出简单的ajax请求。 https://insightsoftwaresolutions.atlassian.net/rest/api/2/issue/createmeta?projectKeys=TES&issuetypeNames=Bug&expand=projects.issuetypes.fields https://insightsoftwaresolutions.atlassian.net/rest/api/2/issue/createmeta?projectKeys=TES&issuetypeNames=Bug&expand=projects.issuetypes.fields

It receives the JSON response when i just put the URL on browser navigation bar and press enter but it's not working when i try to make a jquery ajax call. 当我只是将URL放在浏览器导航栏上并按回车键时,它会收到JSON响应但是当我尝试进行jquery ajax调用时它不起作用。 It's not having any console errors. 它没有任何控制台错误。

<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>  

UPDATE: 更新:

I changed the datatype:'jsonp' to datatype:'json'. 我将数据类型:'jsonp'更改为datatype:'json'。 Then i get the following error. 然后我得到以下错误。

Origin http://localhost:3029 is not allowed by Access-Control-Allow-Origin.

Your Server does not support JSONP . 您的服务器不支持JSONP Either change that 要么改变它

OR 要么

Add headers at nginx to support CORS on the server side. 在nginx添加标头以支持服务器端的CORS。 OR you can add the CORS header on server side. 或者您可以在服务器端添加CORS标头。

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");

Once you do that you can access your code using simple 完成后,您可以使用简单的方法访问代码

$.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