Jump to content
MakeWebGames

jQuert+php+mysql AJAX chat tutorial


dnenb

Recommended Posts

I just created a chat to one of my games by following this tutorial:

That dude is awesome! Check out his other tutorials.

At the end you glossed over the delete saying you can just add this to that but someone who is watching will most likely not know how to, you are not returned the id from ajaxPost.php to use when making the new line. Would it not be best to reload the div with $('#messages').load('ajaxGet.php'); same with after deleting.

Link to comment
Share on other sites

At the end you glossed over the delete saying you can just add this to that but someone who is watching will most likely not know how to, you are not returned the id from ajaxPost.php to use when making the new line. Would it not be best to reload the div with $('#messages').load('ajaxGet.php'); same with after deleting.

Yup. As he says in the tutorial: This is a simple example :) And I learned something from it. Worth watching!

Link to comment
Share on other sites

  • 4 months later...

That is a good simple little tutorial. Just make sure you go read up on sql injection before putting it on your website.

// A good start to preventing sql injection (php)

$post_var = mysqli_real_escape_string($_POST['var']);

 

Also if you wanted to make it real time chat you could setup a javascript setInterval on the load function which checks for updates.

http://www.w3schools.com/jsref/met_win_setinterval.asp

Using some jQuery.

 

var myVar = setInterval(function(){loadChat()}, 1000);

function loadChat() {
 $.post('?','action=get_chat',function(d){
   $('#msg').html(d);
 });
}

 

I would just advice not to try to get too many users on that at one time because it would tax your website. If you want to make a larger scale chat check out socket.io with nodejs. It is more suited for real time communication browser based. There are other ways as well but this is my personal favorite.

I know I did not give all the code available so feel free to ask questions and at worse I will write a tutorial when I get some time.

Edited by bbgengine
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.

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