How can i call Jquery AJAX external URl in asp.net?

Can jquery ajax code call a webservice from another domain name or another website? Below is the code i amm using,

$.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));
    }
});

How to solve this one?

1 answer

  • answered 2018-04-17 05:49 Aneesh R S

    Sure it can

    Your problem is due to the absence of double quotes in the url. url field in the ajax should be string value. Try the code below

    $.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));
        }
    });