Click here to Skip to main content
13,000,636 members (56,681 online)
Rate this:
Please Sign up or sign in to vote.
I've started to work on a private project. However, in the first stage already faced a problem.

The returned data is in XML format (not that bad, but takes alot of effort to parse to usable objects)
The remote server doesn't accept any ORIGIN except for himself, so the browser throws the error: Origin * is not allowed by Access-Control-Allow-Origin.

the (*) could either be null, localhost, or my website.
So I have been searching, but unable to find any results.

It appears there is no alternative for the jsonp argument when using $.ajax, and the name $.getJSON is as it says, ment to retrieve JSON, not XML.

So i'm wondering, it there any other alternative method to retrieve the external XML data while disabling the ORIGIN property when sending the request?

Yours Sincerley, Lars

I've noticed it is possible to obtain the contents with the PHP function: file_get_contents. But I'd really like to know if there is a different way using JQuery.

And if anyone knows how I could let JQuery communicate with the returned PHP file contents, please feel free to enlight me :']
Posted 29-Mar-13 13:52pm
Updated 29-Mar-13 15:51pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The methods $.ajax, even less $.getJSON are unrelated to XML. You use Ajax to download some data, then post it as XML, as you correctly put it.

Hard or not the parsing is, you have to do it; "usable objects" don't parse themselves. :-)
Here is how you do it with jQuery:[^].


The code sample in the article generally illustrates how to use XML. This is a bit more detailed example:[^].

By the way, this is the plug-in to convert XML to JSON:[^].

larssy1 29-Mar-13 20:43pm
But how could i retrieve the data in the first case??
Sergey Alexandrovich Kryukov 29-Mar-13 22:37pm
Using Ajax. What exactly is not clear? The data send via Ajax depends on requirement of the service/site...
larssy1 30-Mar-13 4:37am
Well.. what is not clear.. is how I could retrieve the data from the remote server, but remove the Origin headers from the request.

For JSON, the jsonp dataType is the solution.
What is the solution for XML?
Sergey Alexandrovich Kryukov 30-Mar-13 21:28pm
I don't understand the point with removing the headers...
I added couple of references to the answer, please see after [EDIT].
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

This is not an actual solution for my problem given. But it is a way to bypass the origin using PHP.

In my javascript, I've requested my PHP code using the following:

function Communication () { = new Global();
    this.allowedParameters = ["Character"];
    this.retrieveXMLFromRemoteServer = function (section, keyId, vCode) {
        if (, this.allowedParameters)) {
            $.get(this.formatCommunicationURL(section, keyId, vCode), function(data) {
    this.formatCommunicationURL = function (baseUri, keyId, vCode) {
        return "server/" + baseUri + ".php?keyId=" + keyId + "&vCode=" + vCode;

Whichs called for example: server/Character.php?keyId=00001&vCode=002342345234

The PHP file contains the following code:

namespace my_api;

class Character {
    function retrieveCharacters ($keyId, $vCode) {
        return file_get_contents("https://external_url/Characters.aspx?keyId=" . $keyId . "&vCode=" . $vCode);
$char = new Character();
echo $char->retrieveCharacters($_GET['keyId'], $_GET['vCode']);

This file retrieves the data from the external URL, and then echo's the output so there is a response text JS will be able to use.

Hope this helps for some of you :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170624.1 | Last Updated 30 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100