how to implement cross domain

how to implement cross domain

Postby priya » Tue Dec 03, 2013 2:02 am

Hi ,

I am checking my application by putting the app in my server. when i am trying to access some xml file in other domain (using ajax) it is not calling that but when i tried to access the json with the same domain name it is calling that. How i can make calls to the data which is hosted in some other domains
priya
 
Posts: 16
Joined: Sun Aug 25, 2013 10:53 pm

how to implement cross domain

Postby priya » Tue Dec 03, 2013 2:02 am

Hi ,

I am checking my application by putting the app in my server. when i am trying to access some xml file in other domain (using ajax) it is not calling that but when i tried to access the json with the same domain name it is calling that. How i can make calls to the data which is hosted in some other domains
priya
 
Posts: 16
Joined: Sun Aug 25, 2013 10:53 pm

Re: how to implement cross domain

Postby Support_STA » Tue Dec 03, 2013 2:02 am

Hello,

When using AJAX to retrieve data from another domain you will always run into security issues. Please review section 3.3.3 - CORS of the Developer Guidelines. This deals with cross domain AJAX.

Alternatively you can use a cross domain proxy script (e.g. PHP) to retrieve the data from the other domain. There are many examples of this on the web.

Regards,
STA QA
Support_STA
 
Posts: 136
Joined: Fri Aug 09, 2013 3:56 am

Re: how to implement cross domain

Postby priya » Tue Dec 03, 2013 2:02 am

Hi,

I read the document. There they mentioned like i have to do some changes in the server side. But in my case i am getting the xml file dynamically so dont know from which server it is coming and cant able to change anything in the server. How can implement this.

Can you please help me in this.
priya
 
Posts: 16
Joined: Sun Aug 25, 2013 10:53 pm

Re: how to implement cross domain

Postby Support_STA » Tue Dec 03, 2013 2:02 am

Hi Priya,

What you require is to place a PHP (or other server-side script) on your own server where your app is hosted. This script will retrieve the XML file from the other domain and pass it on to your app in the same domain. Numerous examples of such scripts exist on the web. For example:

\"http://benalman.com/projects/php-simple-proxy/\"
\"http://www.abdulqabiz.com/blog/archives/2007/05/31/php-proxy-script-for-cross-domain-requests/\"

Best regards,
STA QA
Support_STA
 
Posts: 136
Joined: Fri Aug 09, 2013 3:56 am

Re: how to implement cross domain

Postby priya » Tue Dec 03, 2013 2:02 am

Hi,

Sorry. I am not getting the solutions yet. I will clearly explain my issue with example. Using the ajax call i am calling one url in a function.

function getadv(){
var url;
$.ajax({
type: \"GET\",
url: \"www.staging.com/MPFullScreenAds?date=2013-10-31&resolution=1080p\",
async: false,
success: function(message){
var url=message.data.url;
}

});
vid_samp_url(url);
}

Using the first ajax call i am getting the xml url which i have to parse as the url for the second ajax call. I am getting the xml url dynamically. My application hosted server and the first ajax url are in the same server.

function vid_samp_url(xml_url){
$.ajax({
type:\"GET\",
url: xml_url,
async: false,
success: function(xml){
console.log(\"xml call succeed\");
vid_url=$(xml).find(\"MediaFiles\").text();
}
}
From the second ajax i have to get the video path but it is not calling the xml url which is in the another server. I am not using php in my app.

Can you please help me in this
priya
 
Posts: 16
Joined: Sun Aug 25, 2013 10:53 pm

Re: how to implement cross domain

Postby Support_STA » Tue Dec 03, 2013 2:02 am

The problem may be that you are using jQuery version 1.8 or newer in which synchronous ajax calls are deprecated. Please review the jQuery.ajax () documentation for the async property. A solution could be to move the call to vid_samp_url into the success function of getadv and setting async to true or removing it.

Please avoid synchronous requests, as they may potentially hang the browser for a long time.

Regards,
STA QA
Support_STA
 
Posts: 136
Joined: Fri Aug 09, 2013 3:56 am

Re: how to implement cross domain

Postby Support_STA » Tue Dec 03, 2013 2:26 am

Hello,

When using AJAX to retrieve data from another domain you will always run into security issues. Please review section 3.3.3 - CORS of the Developer Guidelines. This deals with cross domain AJAX.

Alternatively you can use a cross domain proxy script (e.g. PHP) to retrieve the data from the other domain. There are many examples of this on the web.

Regards,
STA QA
Support_STA
 
Posts: 136
Joined: Fri Aug 09, 2013 3:56 am

Re: how to implement cross domain

Postby priya » Thu Dec 19, 2013 11:23 pm

Hi,

I read the document. There they mentioned like i have to do some changes in the server side. But in my case i am getting the xml file dynamically so dont know from which server it is coming and cant able to change anything in the server. How can implement this.

Can you please help me in this.
priya
 
Posts: 16
Joined: Sun Aug 25, 2013 10:53 pm

Re: how to implement cross domain

Postby Support_STA » Fri Dec 20, 2013 1:46 am

Hi Priya,

What you require is to place a PHP (or other server-side script) on your own server where your app is hosted. This script will retrieve the XML file from the other domain and pass it on to your app in the same domain. Numerous examples of such scripts exist on the web. For example:

http://benalman.com/projects/php-simple-proxy/
http://www.abdulqabiz.com/blog/archives ... -requests/

Best regards,
STA QA
Support_STA
 
Posts: 136
Joined: Fri Aug 09, 2013 3:56 am

Next

Return to App development questions



cron