0

I'm trying to implement a jsonp function but I'm getting a 401 response,

code on website1:

   goaap: function () {
        $.ajax({
            Authorization: '',
            type: 'GET',
            url: 'http://www.wedsite2.com/global/js/live.js?callback=goaa',
            async: false,
            contentType: "application/json; charset=utf-8",
            dataType: 'jsonp',
            success: function (msg) {
                    //do something
              }
        });
    },

code on website2:

goaa: function () {
        var request = null;
        while (request === null) {
            request = $.ajax({
                url: "default.aspx/goaa",
                data: '{AID: "' + $('#details').data('aid') + '"}',
                dataType: 'json',
                type: "POST",
                contentType: "application/json; charset=utf-8"
            });
        }
        return request;
    },

I have looked at a number of examples and they suggest the jsonp implementation is straight forward, have I missed something in my implementation which is causing the 401 response?

Extra information from firebug:

Response:

{"Message":"There was an error processing the request.","StackTrace":"","ExceptionType":""}

JSON:

Message "There was an error processing the request." StackTrace "" ExceptionType ""

Post: JSON: AID "-1" Source: {AID: "-1"}

Ben Close
  • 354
  • 5
  • 16
  • 1
    Did you check out for CrossDomain dependency??? http://stackoverflow.com/a/11736771/228656 also http://stackoverflow.com/questions/3506208/jquery-ajax-cross-domain ??? – sam Nov 12 '13 at 13:59
  • You cannot use `async:false` together with `jsonp`, and in your second snippet the `while` loop hardly makes any sense since `$.ajax` does always return something. – Bergi Nov 12 '13 at 14:13
  • 1
    What is `Authorization: ''` supposed to do? Whatever it is, JSONP probably cannot handle it. Read more on JSONP: http://en.wikipedia.org/wiki/JSONP – Bergi Nov 12 '13 at 14:15
  • @Bergi I misread the doc on [Link](http://api.jquery.com/jQuery.ajax/) about async and it was in the example I found for JSONP, Authorization was in another example I found trying to solve this I have removed them both but still no change. – Ben Close Nov 12 '13 at 14:25
  • @sam I am looking in to CrossDomain dependency thank you for the links. – Ben Close Nov 12 '13 at 14:26
  • `$.ajax` doesn't have an `Authorization` paramter. – Rocket Hazmat Nov 12 '13 at 15:49

0 Answers0