AJAX and NS_ERROR_DOM_BAD_URI error

无人久伴 提交于 2020-01-11 08:32:07

问题


I have been having the following problem, i think it's probably due to the fact that my approach may be misguided, but hopefully with your help i can sort this out!

Basically, for my site i have a search provider (who has been paid, so i am not breaking any terms of use). When the search form is subbmitted i am directed to their domain where the results are displayed.

Whilst i can customise the look of the returned results, there is only so far i can take this, and will never get it fitting in fully with the look and feel of my site.

So, i thought, instead of doing the regular GET via the form, i would do an AJAXified GET and then inject the returned response into a div on the page - allowing me to maintain the look and feel and never leave our domain.

This works fine in IE but in firefox i get "text/html (NS_ERROR_DOM_BAD_URI)" as an error. Having done some research i have discovered this is due to the AJAX request hitting a site outside of our domain.

Thus, is there a better approach i can take to achieve the same effect? or is there a way i can get firefox and my AJAX request to play nice? What is really strange is that if i observe the request in the HttpFox (a neat FF add on), it reports the above error, but looking at the content returned it is all there as expected - so why can't i access it!!

I would really like to get this to work as it is a whole lot simpler than rewriting all our CSS and stuff to get their results page looking almost like our site. Any help in this area would be much appreciated.


回答1:


You'll have to use JSONP to do cross domain as far as I know - it's a security exception in AJAX. JQuery handles it nicely but, you will have to have the server reply modified to match it.

I have done an OSS project for Social Actions that does this using a PHP proxy. You can look at it here: http://os.adamaltemus.com/social-actions/




回答2:


This error occurs if you have given different domain name in the code. http://hiox.org/index.php?id=2737




回答3:


It's also possible if you're currently on a http webpage and are trying to send an AJAX call to a https website on the same domain.



来源:https://stackoverflow.com/questions/1105055/ajax-and-ns-error-dom-bad-uri-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!