ASK FOR HELP IN AJAX (CROSS DOMAIN)

Discussion and feedback on Construct 2

Post » Fri Dec 06, 2013 6:15 pm

i still can't figure out how to get data from server (maybe cause the client and server are not in the same server!! but i do not know how to handle it)... when i use javascript below it works!!
...
but when i use the ajax plugin it return error?? can anyone help me ....it has confused me so much....
B
3
Posts: 4
Reputation: 308

Post » Fri Dec 06, 2013 6:15 pm

function get_data(name,value) {$.ajax({
           type : 'get',
           async:false,
           url : 'h..t..t..p..:/../..1..1..5.28.160.34:2011/play_pie',
           data: ''+name+'='+value+'',
           dataType : 'jsonp',
           jsonp: 'jsoncallback',
           success : function(json){alert('sucess!!!'+json.data.number.one)},
           error:function(){      
                alert('fail');
           }});
}
B
3
Posts: 4
Reputation: 308

Post » Fri Dec 06, 2013 6:59 pm

If you are calling a PHP file through ajax on another host, add somewhere at the top:


header('Access-Control-Allow-Origin: *');


This will allow PHP to perform cross domain requests.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,592

Post » Sat Dec 07, 2013 7:00 am

THANK U! but i still can't understant it... how to add 'header('Access-Control-Allow-Origin: *'); ' and my server file written in python,
   and this is image is in Construt2
it doensn't work
   this is in Javascript test it can get data..
B
3
Posts: 4
Reputation: 308

Post » Sat Dec 07, 2013 7:03 am

SORRY I'm not allow to submmit URL please remove '_' below and you can see my images
ht_tp://dgardener.duapp.com/img/23.png
ht_tp://dgardener.duapp.com/img/12.png
B
3
Posts: 4
Reputation: 308

Post » Sat Dec 07, 2013 8:02 am

For python add:

self.response.headers['Access-Control-Allow-Origin'] = '*'



Anywhere in your handler. (within your python script)
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,592


Return to Construct 2 General

Who is online

Users browsing this forum: cesisco and 1 guest