How do I get Ajax to correctly callback perfectly good Url

Get help using Construct 2

Post » Sun Feb 21, 2016 4:53 pm

I doing a simple Ajax call to pull some Json data from a running web server. Here is the code...

Image

Notice I'm storing the url in the DBG variable. In the debug console, I can grab the url in DBG, paste it into Chrome and the exact Json data expected is displayed.

However...

In the code the C2 Ajax error callback is always called, never the success. RETURN_VAL_4 has the "Login error: " prefix and then blank. Nothing in Ajax.LastData. This makes no sense when it works perfectly fine in Chrome.

What is happening?

Thank you for helping me past this. I'm stuck :-/
B
13
S
4
Posts: 280
Reputation: 1,578

Post » Sun Feb 21, 2016 5:33 pm

Have you looked at the console to see if any errors are being generated? Sounds like a domain issue, possibly.
ImageImageImage
B
71
S
22
G
240
Posts: 3,734
Reputation: 133,994

Post » Sun Feb 21, 2016 8:00 pm

Thank you @blackhornet. I think you're right about that. However there is no combination of res.header settings that will allow C2 app running in preview ( http://localhost:50000 ) to connect. I can't make it work :-/
B
13
S
4
Posts: 280
Reputation: 1,578

Post » Sun Feb 21, 2016 8:09 pm

Chrome + Allow-Control-Allow-Origin: *
Allows to you request any site with ajax from any source.
B
66
S
24
G
7
Posts: 1,514
Reputation: 11,039

Post » Sun Feb 21, 2016 8:38 pm

Ok it looks like I have the right CORS headers now.

It's Node/Express, this works...

Code: Select all
      
    console.log('Setting headers on server res now...');
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    next();

B
13
S
4
Posts: 280
Reputation: 1,578


Return to How do I....?

Who is online

Users browsing this forum: Ashley, Bootfit, mcscooter, TRMG and 25 guests