views:

103

answers:

2

I have following script

$.ajax({
   type:"GET",
   url:"views/jquery/js/private/visual_constructor/proxy.php",
   data:null,
   timeout:55000, 
   dataType:"xml",
   error:function(XMLHttpRequest, textStatus, errorThrown){
         alert("error="+XMLHttpRequest+" error2="+textStatus+" error3="+errorThrown);
   },
   success:function(response){                      
         alert('sucess');
   }
});

and the content of the proxy.php is following.

<?php
   header('Content-type: application/xml');
   echo file_get_contents('http://server.name/somefile.php');
?>

It connects to another server where somefile.php generates some xml content and prints it.

It works perfectly in Chrome, but in Mozilla it shows me my error alert.

What is wrong here?

update 1

I am using firebug and it says that everything is just OK. Even it shows the response from the server. And here is what my error alert prints:

error=[object XMLHttpRequest] error2=parsererror error3=parsererror

update 2

When I open http://server.name/somefile.php from the Mozilla it shows me this message:

XML Parsing Error: not well-formed
Location: http://authoringtool/views/jquery/js/private/visual_constructor/proxy.php
Line Number 8, Column 94:  <xs:annotation><xs:documentation xml:lang="en">Network     Type</xs:documentation></xs:annotatin>

But again when I open it from Chrome it doesn't show me the error but prints the content of the somefile.php

A: 

I think you're doing a cross-server request (more importantly, a cross-domain request ), and as such, you need to do extra security stuff.

https://developer.mozilla.org/En/HTTP_access_control

https://developer.mozilla.org/En/Server-Side_Access_Control

http://www.w3.org/TR/cors/

http://arunranga.com/examples/access-control/

Firebug

Also, with Firebug, debugging is better as objects, then you can inspect the returned objects.

console.log({ "error": XMLHttpRequest, "error2": textStatus,  "error3": errorThrown });
Kent Fredric
But in order to avoid this problem of cross-domain request I created proxy.php file which connects to other server and prints its content. So from ajax I am getting the content of my proxy.php file which is in the same domain.
Bakhtiyor
A: 

Try setting the content type from the query itself:

$.ajax({
   type:"GET",
   url:"views/jquery/js/private/visual_constructor/proxy.php",
   data:null,
   timeout:55000,
   contentType: "application/xml;charset=UTF-8",
   dataType:"xml",
   error:function(XMLHttpRequest, textStatus, errorThrown){
         alert("error="+XMLHttpRequest+" error2="+textStatus+" error3="+errorThrown);
   },
   success:function(response){                      
         alert('sucess');
   }
});
Satyajit
Showing error message like this:error=[object XMLHttpRequest] error2=parsererror error3=parsererror
Bakhtiyor