Solved

Ajax call doesn't work in Firefox

Posted on 2009-04-02
8
2,277 Views
Last Modified: 2013-12-07
Hello Experts
We have a webservice that was developed and tested in IE. After development we found out that it doesn't work in firefox. There is no error on the page but the drop down data that is returned via webservice call is empty.. we're using jqoery jquery-1.3.2.js is used for the webservice call...

I would appreciate if someone knows about any known bug or put my on the path to find the answer..
when I look at the firefox error console. it says:
uncaught exception: [Exception... "Access to restricted URI
denied"  code: "1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)"

Thanks
Rod
$.ajax({
                    type: "POST",
                    url: "http://..../TaxonomySearchService.svc/web/GetAssociation",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    data: '{ "SubjectSide_TargetID":"' + SubjectSide_TargetID + '", "...."'"}',
                    success: function(data, associationValues) {
 
 
                        activityOptions[index++] = new Option(heading, "");
                        
                        $.each(data.d, function(i, association) {
                            var value = association.TARGET_VOCAB_ID;
                            var text = association.TARGET;
 
                            var activityOption = new Option(text, value);
                            activityOptions[index++] = activityOption;
                        });
 
                        LoadData(dropdown, activityOptions);
                    },
                    error: function(msg) {
                        alert(msg);
                    }
                });

Open in new window

0
Comment
Question by:roddios
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 18

Expert Comment

by:Morcalavin
ID: 24051634
Is the url on the same domain?

Sometimes referencing a link with the http:// or http://www prefixes may cause the cross-domain scripting security to fire.

If it's on the same domain, try using just an absolute path reference to the script:
url: "/TaxonomySearchService.svc/web/GetAssociation"
0
 

Author Comment

by:roddios
ID: 24051805
Thanks for your response. no the url is actually on a remote machine
0
 
LVL 18

Expert Comment

by:Morcalavin
ID: 24051895
You can't do ajax calls to a remote machine.  Ajax only works on the same domain.  In order to do ajax calls to another domain, you must call a proxy script on your domain that runs server side.  That proxy script contacts the remote domain and returns the information to your local domain.
0
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 

Author Comment

by:roddios
ID: 24052152
I'm on VPN connected to the domain. What I meant was that the service is not running locally so I don't think I can omit the http from the url. My ajax call works in IE7  
0
 
LVL 18

Expert Comment

by:Morcalavin
ID: 24052306
If your javascript resides on http://www.mydomain.com and you want to access http://www.yourodmain.com, you cannot do that without a proxy script like I mentioned in the above post.  Browsers have a cross-domain policy that prevents the xmlhttprequest object from contacting other domains.  If it works in IE7 and there are two domains involved, that's a bug.
0
 

Author Comment

by:roddios
ID: 24052592
I have absolutely no idea what a javascript proxy is.. could you explain /  give examples
0
 
LVL 18

Accepted Solution

by:
Morcalavin earned 500 total points
ID: 24052708
The proxy is actually a script that resides on the server side.  It can be written in any server side language that has an http client object available for it.  Heck, you could even use CGI/wget combo.  Anyway, here is a brief example.

weather.com has a web service, we'll call it http://weather.com/getweather.aspx.  I would like to use this webservice on my website located at mysite.com.  I would like to use javascript/ajax to query the xml from the weather.com service.  However, ajax cannot cross domains, so I'm out of luck.  Or am I?

My website has perl/php/asp.net/etc.  I can use this server side language to query weather.com for me.  Let's say I'm using perl.  My perl code may be at http://mysite.com/cgi-bin/getweatherinfo.cgi and my script may look something like this:

#!/usr/bin/perl
use LWP::Simple;
my $html = get('http://weather.com/getweather.aspx'); //does the same thing that an ajax call does, but server side scripts are not bound by the same domain policy that ajax in a browser is.
print $html if defined $html;  //pring out my html

In my ajax, instead of saying:
ajaxobject.open('get', 'http://weather.com/getweather.aspx', true);
I would say:
ajaxobject.open('get', 'http://mysite.com/cgi-bin/getweatherinfo.pl', true);

Ajax calls MY script, which is on the same domain.  My CGI script goes out and retrieves the information and prints it out.  It can do this because it is not bound by the same security policy javascript running in the browser is.

Yahoo has a nice article of it:
http://developer.yahoo.com/javascript/howto-proxy.html


0
 

Author Comment

by:roddios
ID: 24053245
thanks.. good stuff
0

Featured Post

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
This article discusses how to create an extensible mechanism for linked drop downs.
This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question