Coly010 Posted July 30, 2013 Posted July 30, 2013 I'm trying to pass a couple of PHP Variables to my javascript function which is: function showChat(friendid, chat_id) { var fr_id = friendid; var c_id = chat_id; $.post("chat.php", { friend_id: fr_id, ch_id: c_id }, function(data, status) { $("#chat_box").load("chat.php"); $("#chat_box").show(); }); } The PHP code is: <div class='f_bar' onClick='showChat({$cu2_id},{$c_id})'> and the errors im getting are: Notice: Undefined index: friend_id in C:\xampp\htdocs\chat\chat.php on line 12 Notice: Undefined index: ch_id in C:\xampp\htdocs\chat\chat.php on line 13 Can anyone tell me why I am getting these errors, as i believe I am passing the variables correctly. and even passing them by doing: <div class='f_bar' onClick='showChat(" . $cu2_id . "," . $c_id . ")'> does not seem to work. Quote
Coly010 Posted July 30, 2013 Author Posted July 30, 2013 in what sense? like <?php echo $cu2_id; ?> or some other way? Quote
Guest Posted July 30, 2013 Posted July 30, 2013 in what sense? like <?php echo $cu2_id; ?> or some other way? Yes that sense. Quote
Coly010 Posted July 30, 2013 Author Posted July 30, 2013 have tried that, but i'm getting the same error. Quote
sniko Posted July 30, 2013 Posted July 30, 2013 (edited) Considering the errors are on chat.php, do some debugging over there, too. var_dump($_GET); var_dump($_POST); See what's happening over there. Next, view the source, and see if the parameters are being passed correctly. If there are, something is up with $.post parameters. If something is up with the $.post parameters, view the console log, and find out. Edited July 30, 2013 by sniko Quote
Coly010 Posted July 30, 2013 Author Posted July 30, 2013 I've set up an alert telling my the response of the $.post is and it is saying that it is sending the data successfully, however the variables just dont seem to be getting set Quote
sniko Posted July 30, 2013 Posted July 30, 2013 I've set up an alert telling my the response of the $.post is and it is saying that it is sending the data successfully, however the variables just dont seem to be getting set What does a var_dump yield? Quote
Coly010 Posted July 30, 2013 Author Posted July 30, 2013 array(0) {} I dont understand this error at all though, because I have a near identical other piece of code and that works fine, the only difference is the name of the variables Quote
Coly010 Posted July 31, 2013 Author Posted July 31, 2013 I've kind of worked out what's wrong. The $.post() is not actually sending the values to the chat.php file. I have no idea why this is though. What would stop the jquery $.post() from sending the values, yet returning it as a success? I'm extremely confused. Is there another way to do this, to the same effect? Quote
Coly010 Posted July 31, 2013 Author Posted July 31, 2013 Worked out the problem. I'm posting the data ok, but after it I'm trying to load the file, which isnt having any variables sent to it. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.