Jump to content
MakeWebGames

Recommended Posts

Posted

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.

Posted
in what sense? like <?php echo $cu2_id; ?> or some other way?

Yes that sense.

Posted (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 by sniko
Posted

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

Posted
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?

Posted

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

Posted

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?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...