weixin_33744141 2013-10-02 03:16 采纳率: 0%
浏览 8

Ajax jQuery调用不起作用

i'm trying to make a simple ajax request to the following URL. 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. 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'. Then i get the following error.

Origin http://localhost:3029 is not allowed by Access-Control-Allow-Origin.
  • 写回答

1条回答 默认 最新

  • weixin_33692284 2013-10-02 04:09
    关注

    Your Server does not support JSONP. Either change that

    OR

    Add headers at nginx to support CORS on the server side. OR you can add the CORS header on server side.

    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
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题