Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewriting ajax requests #22

Open
requiredfield opened this issue Sep 8, 2014 · 4 comments
Open

rewriting ajax requests #22

requiredfield opened this issue Sep 8, 2014 · 4 comments

Comments

@requiredfield
Copy link

I'm trying to use xmlhttprequest.js to intercept an ajax request and request a different url instead. The code all looks correct, but it's failing silently with no hints in the developer console. Here is a live preview along with the code:

http://embed.plnkr.co/5Vpdohf69anQlUutHl7Y/preview

Am I doing something wrong, or is this just not possible?

Thanks in advance for any tips.

@ilinsky
Copy link
Owner

ilinsky commented Sep 8, 2014

When I try your page, I see "XMLHttpRequest cannot load https://httpbin.org/bytes/8. Request header field X-Requested-With is not allowed by Access-Control-Allow-Headers. " message in console. This may have something to do with configuration of access control on the server.

@requiredfield
Copy link
Author

Thanks so much for taking a look @ilinsky, and sorry I linked to a bad plunker! Fixed my example.

Here is a version where the conditional rewrite code is commented out and clicking the button successfully loads https://httpbin.org/ip:

http://embed.plnkr.co/5Vpdohf69anQlUutHl7Y/preview

When you uncomment out XmlHTTPRequest.js and the rewrite logic, after clicking the button the state stays stuck at "awaiting result", whether or not you check the rewrite checkbox:

http://embed.plnkr.co/dglwlMoR14nTHymvkssW/preview

This time it's rewriting a cross-origin request to a same-origin request, so it should be even more likely to work.

Looking in Developer Tools, there are no errors in the JavaScript console, and the XHR is never even opened or sent.

Do you have any idea what's going on here? Thanks again for any help!

@requiredfield
Copy link
Author

(you may have to Shift+Reload on http://embed.plnkr.co/5Vpdohf69anQlUutHl7Y/preview to make sure you get the newest version)

@requiredfield
Copy link
Author

Hi @ilinsky, did that example make sense / demonstrate the issue properly? Much appreciate any time you have to take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants