Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
585 views
in Technique[技术] by (71.8m points)

jquery - Access to restricted URI denied" code: "1012 - Cross domain Ajax request

I Need to do cross domain Ajax request - Here is my code

 $.ajax(
        {
            url: redirectURL,
            data: $('#login-container form').serialize() + querystring,
            type: 'post',
            cache: false,
            dataType: 'jsonp',
            jsonp: 'jsonp_callback',
 });

Error: [Exception... "Access to restricted URI denied"  code: "1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)"  location: "http://testsite/assets/scripts/jquery-1.3.2.js Line: 19"]
Source File: http://testsite/assets/scripts/jquery-1.3.2.js
Line: 19

I have checkout the following links too -

Access to restricted URI denied code: 1012

 $.ajax(
        {
   url: redirectURL+'?callback=?',
            data: $('#login-container form').serialize() + querystring,
            type: 'post',
            cache: false,
            dataType: 'html' });

I have tried Callback in url too . I had already seen all link in stackoverflow regarding this issue.. but not able to overcome this thing Can anyone please help and tell me how to overcome !! Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You won't be able to do a cross-domain POST request in the browser.

If you are making a JSONP call to access a cross-domain URL, you can use JQuery's getJSON method. This would allow you to make a GET request only. If you can submit your login information to the redirectURL using GET parameters, you could make this work.

Note that POSTing to remote login forms is perhaps the best example of why browsers disallow cross-domain requests like this. You don't want a page that looks like your bank to be able to actually serve you data from your bank's website -- that would make a very effective phishing page.

On the other hand, if you really want to work around this, you can write some server-side code that, given the input parameters, makes a post request to the redirectURL and funnels back the response.

Please tell me you are not writing a phishing page.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...