Jump to content

JQuery/Javascript onClick function failing


Recommended Posts

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;

				friend_id: fr_id,
				ch_id: c_id
			}, function(data, status)



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.

Link to comment
Share on other sites

Considering the errors are on chat.php, do some debugging over there, too.


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
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Join the conversation

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

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...