Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery ajax call not working?! firefox or xss problem?

My problem is: in firefox i got no response. in ie it worked fine. I want a ajax call to a local script getting some information in plain text or something else. but it won't work. I think cross scripting should not a problem at this point or?

the javascript code is simple:

var targetUrl = "http://localhost/jQueryProxy.php";
var parameters = ""; // later

$.ajax({    
  type: "GET",
  async: true,
  url: targetUrl,
  data: parameters,
  success: function(param1, param2){
    alert(param1);
  }
});

and the php code too:

<?php
   header('Content-type: text/xml'));
   echo "test";
?>
like image 503
stephan Avatar asked Aug 31 '25 10:08

stephan


2 Answers

try var targetUrl = "/jQueryProxy.php";
Also, you can check Firefox's javascript console to look for an error: Ctrl+Shift+J

You can also try looking for jQuery's Ajax error message, by adding an handler (source):

error:function (xhr, ajaxOptions, thrownError){
    alert(xhr.status);
    alert(xhr.statusText);
    alert(thrownError);
 }  

Update: I've done some testing, is seems Firefox blocks Ajax from local files to the web (localhost too, for that matter), but does not throw an exception. Using alert($('*', param1).text()); at success shows the content of the current document, which is weird.
Placing the XML as a local file doesn't work either, the behavior of FF and IE is inconsistency - they act very differently.
Your best bet is to place the html on the server (localhost), on the same port as your xml file (80 here).
Also, when your xml is valid, consider adding dataType:'xml'.

like image 178
Kobi Avatar answered Sep 04 '25 00:09

Kobi


It's because the content type is text/xml but it's not valid XML.

If you want it to be XML, change the echo to be:

<?xml version="1.0" encoding="UTF-8"?>
<foo>test</foo>
like image 25
seth Avatar answered Sep 04 '25 00:09

seth