HaLo2FrEeEk Posted June 30, 2009 Share Posted June 30, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/164181-submitting-data-via-post-but-without-the-form/ Share on other sites More sharing options...
.josh Posted June 30, 2009 Share Posted June 30, 2009 Everything you are wanting to do is what ajax is for. So it sounds like you should be doing it now, instead of "eventually." Your alternative would be to do it in flash. Quote Link to comment https://forums.phpfreaks.com/topic/164181-submitting-data-via-post-but-without-the-form/#findComment-866059 Share on other sites More sharing options...
HaLo2FrEeEk Posted June 30, 2009 Author Share Posted June 30, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/164181-submitting-data-via-post-but-without-the-form/#findComment-866757 Share on other sites More sharing options...
.josh Posted June 30, 2009 Share Posted June 30, 2009 Are you asking if there's an alternative to making a request to the server, as far as finding out if there are updates from something on your server? I suppose you could try using a crystal ball. Quote Link to comment https://forums.phpfreaks.com/topic/164181-submitting-data-via-post-but-without-the-form/#findComment-866762 Share on other sites More sharing options...
HaLo2FrEeEk Posted July 1, 2009 Author Share Posted July 1, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/164181-submitting-data-via-post-but-without-the-form/#findComment-866876 Share on other sites More sharing options...
corbin Posted July 1, 2009 Share Posted July 1, 2009 The HTTP protocol doesn't work like that. I've heard of some solutions like that, but I've never heard of any good ones. Flash/Java can do that though, but not over the HTTP. Quote Link to comment https://forums.phpfreaks.com/topic/164181-submitting-data-via-post-but-without-the-form/#findComment-866879 Share on other sites More sharing options...
joel24 Posted July 1, 2009 Share Posted July 1, 2009 use jquery. its amazing! jquery.com Quote Link to comment https://forums.phpfreaks.com/topic/164181-submitting-data-via-post-but-without-the-form/#findComment-866880 Share on other sites More sharing options...
HaLo2FrEeEk Posted July 1, 2009 Author Share Posted July 1, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/164181-submitting-data-via-post-but-without-the-form/#findComment-867118 Share on other sites More sharing options...
Alex Posted July 1, 2009 Share Posted July 1, 2009 It's not possible with AJAX because there's no live connection, no socket opened. Quote Link to comment https://forums.phpfreaks.com/topic/164181-submitting-data-via-post-but-without-the-form/#findComment-867122 Share on other sites More sharing options...
HaLo2FrEeEk Posted July 1, 2009 Author Share Posted July 1, 2009 Is there a way to do it without flash/java? Quote Link to comment https://forums.phpfreaks.com/topic/164181-submitting-data-via-post-but-without-the-form/#findComment-867435 Share on other sites More sharing options...
.josh Posted July 1, 2009 Share Posted July 1, 2009 Well you could always build your own standalone client in C++ or some other full flavored programming language... Quote Link to comment https://forums.phpfreaks.com/topic/164181-submitting-data-via-post-but-without-the-form/#findComment-867443 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.