【问题标题】:How can i call Jquery AJAX external URl in asp.net?我如何在 asp.net 中调用 Jquery AJAX 外部 URl?
【发布时间】:2018-09-26 23:40:43
【问题描述】:

jquery ajax 代码可以从另一个域名或另一个网站调用 web 服务吗? 下面是我使用的代码,

$.ajax({
    type: "GET",
    contentType: "application/json; charset=utf-8",
    dataType: "jsonp",
    url: "https://developers.google.com/public/oauth2/1/files",
    headers: {
        'Authorization': headerDATA,
        'Content-Type': 'application/json'
    },
    success: function (data) {
        alert("Success");
        for (var i = 0; i < data.items.length; i++) {
            alert(AJAX);
        }
    },
    error: function (e) {
        alert("Failure");
        alert(JSON.stringify(e));
    }
});

这个怎么解决?

【问题讨论】:

    标签: javascript jquery asp.net web-services


    【解决方案1】:

    当然可以

    您的问题是由于网址中没有双引号引起的。 ajax 中的 url 字段应该是字符串值。试试下面的代码

    $.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        dataType: "jsonp",
        url: "https://developers.google.com/public/oauth2/1/files",
        headers: {
            'Authorization': headerDATA,
            'Content-Type': 'application/json'
        },
        success: function (data) {
            alert("Success");
            for (var i = 0; i < data.items.length; i++) {
                alert(data.items[i]);
            }
        },
        error: function (e) {
            alert("Failure");
            alert(JSON.stringify(e));
        }
    });
    

    【讨论】:

    • 不,error: function (e) { alert("Failure"); alert(JSON.stringify(e)); } 这个错误
    • 在错误块中添加console.log(e),并通过控制台查看错误
    • 嗨@aneesh,我得到了解决方案
    • 我还有一个疑问。
    猜你喜欢
    • 2013-08-30
    • 2011-06-04
    • 2012-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多