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";
?>
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:
Its an XSS problem. Generally local html pages are much more sandboxed then public html pages.
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):
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());
atsuccess
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'
.this seems to work on FF:
and php looks like that:
best regards,
bjoern