Chrome doesn't like 'localhost' for a number of functions including cookies. Try changing your links to the IP address of the machine and see if that works. I only use 'localhost' when it is actually required. I normally use the machine IP address because then the pages are accessible from other machines on the network.
derrida
ASKER
hi
no change. and add to it that if i don't do a switch statement it works. but once i use that post veriable, it works of FF but not on chrome.
sorry, that was about another issue i have :) forget about the switch statement.
derrida
ASKER
so when i var_dump my $_POST array:
in chrome: array(0) {
}
empty.
in firefox:
array(1) {
["user"]=>
string(82) "{"name":"Moses","address":"dizingoff 29, NY","lat":23.060143,"lng":29.770557}"
}
Dave Baldwin
For test purposes, I would create an HTML form page and see what you get when you submit that. Like below... note that I put quotes around the "lat / lon" values to get it to work. It works the same in both Firefox and Chrome.
ChromePOSTtest.html
<!DOCTYPE html><html><head><title>Chrome POST test form</title></head><body><h1>Chrome POST test form</h1><form action="addContact.php" method="post"><input type="text" name="user" value='{"name":"Moses","address":"dizingoff 29, NY","lat":"23.060143","lng":"29.770557"}' /><input type="submit" name="submit" value="submit" /></form></body></html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>addContact.php</title></head><body><?php $value = json_decode($_POST['user']);header("Access-Control-Allow-Origin: *");header('Access-Control-Allow-Headers: X-Requested-With');header('Content-Type: application/json');var_dump($_POST['user']);var_dump($value);?></body></html>
well yes, it does work, in that "regular" way ( by the way, with quotes or without the added quotes).
But once I do that in the angular 2 way, works in FF but not in chrome. notice that i'm hard coding the values, since I just want to learn to pass the data in the angular 2 way.
I have no idea why it is passed in FF but not in chrome.
Dave Baldwin
Are you going to try adding 'true' to the json_decode statement? I'm not going to try to duplicate your angular code because most of is not posted and I don't have your database. For testing I always simplify things to something that works and work from there to build something more complicated.
derrida
ASKER
oh i have tried it with the true. same thing: works on FF not in chrome.
Then you need to make a test version of your code that is as simple as possible so you can figure out what is and isn't working. Maybe an 'angular' version of my demo programs. After all Chrome works, Firefox works, PHP works. It's just the combination with your code that isn't working.
derrida
ASKER
so fixed it. and i put it here for anyone else who will encounter the issue.
the problem is that the post array in php expect a key value pair. and that's not what i sent.
so you either send a key value pairs, or if you want to keep the json format, in your php, since there is no key, do: