PHP & JavaScript Application's interaction not functioning

My Java / PHP application isn’t functioning at some point, likely either the JavaScript or the AJAX to PHP communication.

Here are the two files to my website
index [the client]
backend [the server]

I’m not sure what I did wrong. It’s a simple chat client in PHP, JavaScript, AJAX

edit 1
The timestamp in the SQL database is automatic. Thus, it’s not manually inserted. Not an error!

edit 2
I found that the software is able to get content, but I’m unsuccessful in uploading.

Typo in line 37?

35.    var user = "<?php echo $user; ?>";
37."GET", "backend.php?mode=send&user=" + usr + "&msg=" + msg, true);

Shouldn’t the variable name that you append be user, not usr ?

And does the function automatically URL-encode the parameters, in case your msg contains spaces or other URL-unfriendly characters?

1 Like

Thanks. I fixed that typo. The script isn’t working though. And how do you URL encode via JavaScript. There’s nothing else besides the code presented.

Either:"GET", encodeURI("backend.php?mode=send&user=" + usr + "&msg=" + msg), true);

or"GET","backend.php?mode=send&user=" + encodeURIComponent(usr) + "&msg=" + encodeURIComponent(msg), true);
1 Like

Ok. It works now. Just errors with lag. Thanks everyone! @droopsnoot

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.