/    Sign up×
Community /Pin to ProfileBookmark

Firefox $.get problems

Hi guys,

I have the following simple jquery code

[CODE]
$(‘#views-exposed-form-Filtering-page-1’).attr(‘action’, ‘#’).submit(
function(e){
alert(‘working’);
$.get(‘http://www.mysite/my_ajax.php’, function(xml){
alert(‘retrieved : ‘+xml);
});
e.preventDefault();
}
);[/CODE]

All I am doing is overriding the action attribute of a form and when the form is submitted, instead of the default action, I want to retrieve some XML results from my php script.

Strangely, this script does not work in FireFox – it only goes as far as the “alert(‘working’)”.
But, it works perfectly in IE which makes it to the second alert statement and displays the XML.

Can anyone help me out here, please ???

to post a comment
JavaScript

12 Comments(s)

Copy linkTweet thisAlerts:
@KorApr 26.2010 — I want to retrieve some XML results from my php script.[/QUOTE]
make sure your php application returns a valid XML answer. can we see it?
Copy linkTweet thisAlerts:
@captsiskoauthorApr 26.2010 — make sure your php application returns a valid XML answer. can we see it?[/QUOTE]

Visit http://test1omniforce.co.uk/,

Click the "Go" button on the left of the homepage.

Try it in FF and IE to see the differences.
Copy linkTweet thisAlerts:
@KorApr 26.2010 — No... I mean... post the PHP part of the code which generates/echoes the XML response. Some of us here know PHP.
Copy linkTweet thisAlerts:
@captsiskoauthorApr 26.2010 — No... I mean... post the PHP part of the code which generates/echoes the XML response. Some of us here know PHP.[/QUOTE]

OK, the code is below :

[code=php]
$sql = "SELECT
n.title,
n.nid
FROM
node n
WHERE n.type = 'venue'
";

$venues = array();
$nodes = db_query($sql);

while ($aVenue = db_fetch_object($nodes)) {
$venue = node_load($aVenue->nid);
$xmlvenue = $xmlobj->addChild("venue");

$xmlvenue->addAttribute("nid", $aVenue->nid);
$xmlvenue->addAttribute("name", $aVenue->title);
}

return print $xmlobj->asXML();
#print_r ( $xmlobj->asXML() );
#print "responding again!";
[/code]


As you can see, I experimented with a few return/print scenarios - the same results.

Thanks for you help, by the way ?
Copy linkTweet thisAlerts:
@aj_nscApr 26.2010 — I don't get a JS error, but it also never makes it to the ajax request (as observed using Firebug)...in any browser. IE is the only one that throws an error - Permission Denied (omnidrops.js) Line 263 Char 7 - the rest just alert 'working' and then do nothing.
Copy linkTweet thisAlerts:
@captsiskoauthorApr 27.2010 — I don't get a JS error, but it also never makes it to the ajax request (as observed using Firebug)...in any browser. IE is the only one that throws an error - Permission Denied (omnidrops.js) Line 263 Char 7 - the rest just alert 'working' and then do nothing.[/QUOTE]

Yea, something is seriously wrong.

Firstly, IE works just fine on my machine. It alerts "working" and then the full XML output without error.

Secondly, I just arrived back at my desk and read you last message. I tried IE to make sure to make sure my response is accurate. Then I tried FF and guess what - I worked perfectly. ?

I changed nothing since yesterday. It seems FF is at fault here !?
Copy linkTweet thisAlerts:
@NicTltApr 27.2010 — Firefox won't allow a cross-domain $.get() - so were you testing from another test domain before?

You should be able to resolve it by having a relative URL in $.get()
Copy linkTweet thisAlerts:
@captsiskoauthorApr 27.2010 — Firefox won't allow a cross-domain $.get() - so were you testing from another test domain before?

You should be able to resolve it by having a relative URL in $.get()[/QUOTE]


No, the code is native to the same domain. And I was and still am using an absolute path in my $.get call

Just out of curiosity, if I do need to call $.get with a different domain, how do I make that happen ? :rolleyes:
Copy linkTweet thisAlerts:
@aj_nscApr 27.2010 — The way to do that is to use $.get to call a server side script on your server (same domain), get the server side script to grab the data from another domain, and then return it to your Javascript. $.get, as already stated, can't call a script from another domain directly.

I don't know what's going on with your site now, but there's a big red square in the middle of the screen, and nothing happens in Firefox or Chrome when the Go button is pushed, and, as I stated above, Internet Explorer shows an error in the JS console - doesn't even get to the 'working' alert now - you must be in the midst of making changes.
Copy linkTweet thisAlerts:
@captsiskoauthorApr 30.2010 — The way to do that is to use $.get to call a server side script on your server (same domain), get the server side script to grab the data from another domain, and then return it to your Javascript. $.get, as already stated, can't call a script from another domain directly.

I don't know what's going on with your site now, but there's a big red square in the middle of the screen, and nothing happens in Firefox or Chrome when the Go button is pushed, and, as I stated above, Internet Explorer shows an error in the JS console - doesn't even get to the 'working' alert now - you must be in the midst of making changes.[/QUOTE]


Hi there,

thanks for all your help so far - I appreciate it all.

You were right, I was making some changes but nothing has solved the problems still.

The IE error message you mentioned only came to my attention recently.

Basically, it has a problem with this line in my code:
[CODE]
$.get('http://www.test1omniforce.co.uk/sites/all/themes/zen/zen/template_ajax.php',
[/CODE]


The IE error reads:
[CODE]
Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Timestamp: Fri, 30 Apr 2010 08:24:11 UTC


Message: Permission denied
Line: 272
Char: 7
Code: 0
URI: http://test1omniforce.co.uk/sites/all/modules/omnidrops/js/omnidrops.js?g

[/CODE]


I gave template_ajax.php full permissions ( 777 ) but it still does not co-operate.

The path is my domain - it is not external.

FF is better behaved but it sometimes just stops - I don't know if that is my code or if it's the browser
Copy linkTweet thisAlerts:
@captsiskoauthorApr 30.2010 — I really hope no more serious issues comeup from this task ?

For now, I seem to have gotten things working on both browsers.

Just for your information, I though perhaps the code is seeing the path to my php script as absolute to "some domain" and IE was stoping it. So, I experimented and made it relative like the following:
[CODE]$.get('../../../../../sites/all/themes/zen/zen/scriptCode.php',[/CODE]

Secondly, IE still handles xml in its own proprietry way. That had to be accounted for. Clicking "go" under venue search is meant to give you a list of results. That never happended because IE didn't precess the XML my $.get call returned.

I had to do something like the following:
[CODE]
var xml;
if (typeof data == "string") {
xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = false;
xml.loadXML(data);
} else {
xml = data;
}
[/CODE]

data is the xml returned from $.get or $.ajax. FF and IE both return strings as xml(FF just processes it as xml when you do $(data))

So you check if IE is the browser by $.browser.msie.

Thanks for your assistance. :o
×

Success!

Help @captsisko spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...