3 Replies - 671 Views - Last Post: 14 February 2012 - 11:03 PM

#1 sattua  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 83
  • Joined: 20-March 08

$.ajax and xml from server don't work

Posted 14 February 2012 - 08:28 PM

Hi, I'm familiar (maybe not to much) with the ajax thing, now I'm starting to use yhe jquery method: $.ajax, well everything is ok but when I take the xml file to a external server, the $.ajax cant read it, I mean: It don't take the xml data.

so this is ok:

$.ajax({
   type: "GET",
   url: "myfile.xml",
   dataType: "xml",
   success: function(xml) {
	alert("success");
   }
});


As you see, the xml file i'ts next to my script file

but when I take the xml file to a server,, it doesn't work:

$.ajax({
   type: "GET",
   url: "http://somehosting/myfile.xml",
   dataType: "xml",
   success: function(xml) {
	alert("success");
   }
});



I guess I am missing something... but no idea what is it?

thanks in advance.

Is This A Good Question/Topic? 1
  • +

Replies To: $.ajax and xml from server don't work

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,236
  • Joined: 08-June 10

Re: $.ajax and xml from server don't work

Posted 14 February 2012 - 08:29 PM

is that XML file on the same server as the page with that code?
Was This Post Helpful? 2
  • +
  • -

#3 sattua  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 83
  • Joined: 20-March 08

Re: $.ajax and xml from server don't work

Posted 14 February 2012 - 08:32 PM

nop, the script it's gonna use but different pages "all around the world", so yeah others servers
Was This Post Helpful? 0
  • +
  • -

#4 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4333
  • View blog
  • Posts: 12,128
  • Joined: 18-April 07

Re: $.ajax and xml from server don't work

Posted 14 February 2012 - 11:03 PM

The reason Dormilich is asking is because browsers have security built in that prevents Javascript from making cross domain requests. Now if you look up the ajax() method in jQuery you will see it has a setting called "crossDomain" that needs to be set.

But keep in mind that the reason browsers prevent this is so that one script can't try and pull data from other sites without you knowing it. Just imagine, creating a site that has javascript that makes requests to a server to access malicious or virus code. We wouldn't want that.

Read more about some of these dangers if you are interested.

http://msdn.microsof...3(v=vs.85).aspx

:)
Was This Post Helpful? 3
  • +
  • -

Page 1 of 1