Ajax plugin to send header variables

For developers using the Construct 2 Javascript SDK

Post » Wed Feb 12, 2014 2:41 pm

the reaspn why i am not using hdata because i was trying to test first using hardcode values but i was not able to succeeded even using hardcode values.
B
9
S
2
Posts: 108
Reputation: 1,010

Post » Wed Feb 12, 2014 3:00 pm

Content-Type     application/x-www-form-urlencoded
X-UserMail     [email protected]
X-Number     hdj2723
X-Token     80e68a46796cf0085afcb609d29f34523e

Firebug shows this and my php code other hand is

[code]
Yii::log("NO ERROR m = ".$_SERVER["HTTP_X_Token"]." -- ".$_SERVER["HTTP_X_UserMail"],"MyLog");
[/code]

above code just write the data in my log file for these varibales and they are coming as null. Previously the same service when i was calling through the web page by passing X-UserMail etc were working fine ...
B
9
S
2
Posts: 108
Reputation: 1,010

Post » Wed Feb 12, 2014 3:17 pm

Your using Yii framework :) nice stuff, but, does way too much in the background.

try a blank php page and add:

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

var_dump(getallheaders());

?>lennaert2014-02-12 15:21:45
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Post » Wed Feb 12, 2014 3:42 pm

thanks for your rapid replies , yes i am using yii for my game...

I have used the var_dump like as you said on another test page and it displays everything fine if i fetch the page using ajax by test.html javascript...

but using with construct2 , when I send its header firebug shows it is seems fine but response tab does not display anything..it seems like for some reason whenever i set header and send through construct2 the server variables does not reach including the post variables... but shocking these header values in header and post values in post tab of firebug shows they are being sent successfully through firebug... :( still i dont get it why php code is unable to fetch these values when we use construct2 plugin?
B
9
S
2
Posts: 108
Reputation: 1,010

Post » Wed Feb 12, 2014 4:05 pm

Using HData like ""   (empty)

I get this in the response tab:


array(14) {
["Content-Length"]=>
string(1) "4"
["Content-Type"]=>
string(48) "application/x-www-form-urlencoded; charset=UTF-8"
["Accept"]=>
string(63) "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
["Accept-Language"]=>
string(14) "en-gb,en;q=0.5"
["Cache-Control"]=>
string(8) "no-cache"
["Connection"]=>
string(5) "close"
["Dnt"]=>
string(1) "0"
["Host"]=>
string(15) "lennaerthohe.nl"
["Origin"]=>
string(22) "http://localhost:50000"
["Pragma"]=>
string(8) "no-cache"
["Referer"]=>
string(23) "http://localhost:50000/"
["User-Agent"]=>
string(72) "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0"
["X-Forwarded-For"]=>
string(13) "94.212.140.34"
["X-Real-Ip"]=>
string(13) "94.212.140.34"
}



As soon as I put something in the HData entry field t doesnt work.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Post » Wed Feb 12, 2014 4:25 pm

[code]
if(method_ === "POST" && data_ && hdata_)
               {
                    
                    if (request["setRequestHeader"])
                    {
                         request["setRequestHeader"]("Content-Type", "application/x-www-form-urlencoded");
                         request["setRequestHeader"]("X-UserMail", "[email protected]");
                         request["setRequestHeader"]("X-Number", "hdj2723");
                         request["setRequestHeader"]("X-Token", "80e68a4679e864ec99058b609d29f34523e");
                         
                         
                    //     alert("HDPOST "+request["setRequestHeader"]);
                         
                    }
     
                    request.send(data_);
               }
else if (method_ === "POST" && data_)
               {
                    alert("POST");
                    
                    if (request["setRequestHeader"])
                    {
                         request["setRequestHeader"]("Content-Type", "application/x-www-form-urlencoded");
                    }
                         
                    request.send(data_);
               }
               else
                    request.send();
[/code]

this is the code of the plugin suppose if we dont pass hdata then it will run the second condition where it will not insert header variables so that is why your seeing these values. But if you set header then i am sure you will not able to dump this i guess...
B
9
S
2
Posts: 108
Reputation: 1,010

Post » Wed Feb 12, 2014 4:42 pm

yeah as soon as I put something in it seem didnt work.

At least it appeared so, the forms are not getting passed as regular post or get calls, but instead being passed as OPTIONS. (cos of your header)


I get this in the BROWSER console in firefox (CTRL SHIFT J)



Request URL:      http://lennaerthohe.nl/ajaxtest/index.php
Request Method:      OPTIONS
Status Code:      HTTP/1.1 200 OK
Request Headers 17:40:25.000
User-Agent:     Mozilla/5.0 (Windows NT 6.3; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0
Pragma:     no-cache
Origin:     http://localhost:50000
Host:     lennaerthohe.nl
DNT:     0
Connection:     keep-alive
Cache-Control:     no-cache
Access-Control-Request-Method:     POST
Access-Control-Request-Headers:     x-number,x-token,x-usermail
Accept-Language:     en-gb,en;q=0.5
Accept-Encoding:     gzip, deflate
Accept:     text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Response Headers ?124ms
X-Powered-By:     PHP/5.4.24
Vary:     Accept-Encoding
Transfer-Encoding:     chunked
Server:     ngx_openresty
Expires:     Wed, 12 Feb 2014 16:40:42 GMT
Date:     Wed, 12 Feb 2014 16:40:42 GMT
Content-Type:     text/html
Content-Encoding:     gzip
Connection:     keep-alive
Cache-Control:     max-age=0
Access-Control-Allow-Origin:     *



Seems like they are being set.



Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Previous

Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests