Jump to content

Submitting data via POST, but without the form


HaLo2FrEeEk

Recommended Posts

I'm helping a friend build a chat script (as part of a larger project) and I'm looking for a nicer way of deleting individual posts from the chat.

 

Currently I have it check against current userdata to see if the logged-in user is an admin or chat mod.  If he is then it prints a little red x next to each chat post, to delete that post.  The little red x is a link that sends you to chat.php?action=deletepost&postid=#, where # is the chat_id identifier in the database.  It works, but it's ugly, because from then on the URL will read chat.php?action=deletepost&postid=#, which might cause issues when the person refreshes.

 

I was trying for some sort of dynamic form printed before the loop that prints all the chat responses, something like this:

 

  echo "<form name=\"deletepostform\" method=\"POST\" action=\"chattest.php\">";
  echo "<input type=\"hidden\" name=\"action\" id=\"action\" value=\"deletepost\">";
  echo "<input type=\"hidden\" name=\"postid\" id=\"postid\" value=\"\">";
  echo "</form>\n\n";

 

Then in the loop that prints the chat posts I could print a link like this:

 

<a href=\"".$_SERVER['PHP_SELF']."\" onclick=\"javascript:document.deletepostform.postid.value='".$row['chat_id']."';document.deletepostform.submit();\" title=\"delete post\">

 

which SHOULD set the value of the form's postid field to the current post id, then submit that form...unfortunately this doesn't work everytime.  In fact it never works on the first click, I have to click it multiple times to get it to work.  I'd like to stay away from printing a new form for each chat item, since I'd need unique names for each one and I don't like that.

 

Basically I need a way to submit POST data without using a form.  Is this possible?  I know that I can use REQUEST or GET but I don't like that since like I said, the url will be messed up after that.  I want the URL to always stay at chat.php.

 

Eventually I will be changing this all to AJAX, which will simplify things a LOT, but right now I just need it working how it is.  Can anyone help me out?

Link to comment
Share on other sites

Bleh flash, I don't know flash.

 

Ok, I'll get started on the AJAX then.  One quick question, is there an easy method of push delivery with AJAX, so that I don't have to check for updates every 5 seconds, but rather when a new post is made it's automatically sent to all browsers?  I've been looking online but I can't find how to do it.

Link to comment
Share on other sites

No...I'm asking:

 

is there an easy method of push delivery with AJAX, so that I don't have to check for updates every 5 seconds, but rather when a new post is made it's automatically sent to all browsers?

 

Sorry, thought that was pretty clear.  Push delivery basically keeps a connection alive to the database and when new data is put into the database, it's automatically pushed to the client's browser, instead of the broswer pulling it from the database.

Link to comment
Share on other sites

I have jQuery, but it doesn't remotely relate to the question I was asking.  As far as I know jQuery doesn't have any ability to perform push delivery via AJAX.

 

How does IRC do it?  Like website-embedded IRC clients?  I've been going to this site called justin.tv for a month or so now and they've got a chat box that's IRC-based and has instant updates.  I'm pretty sure it doesn't use flash, but I might be mistaken.  I might just have to resign myself to the fact that I'll have to update it every 5 or 10 seconds.  I suppose that's ok.  I mean, you're not getting much data, so I think I can handle that.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.