Web Shoutbox Idea
Web Shoutbox Idea
你好,我正在考虑为我的网站制作一个shoutbox。我不想使用任何其他的,因为它不太适合我之前存在的成员数据库。我想了一些主意,但我真的不确定有什么更好的方法。我想提交一份表格,在没有"获取"的情况下发送一条消息。我也无法重新加载页面。这就是AJAX的用武之地:p
我想把我网页上的表格设置为:
<form method="post" onsubmit="return sendShout()" >
<input type="text" name="Shout" id="Shout" />
</form>
我的javascript如下:
<script>
function sendShout()
{
if(ShoutTime == 0)
{
var http = new XMLHttpRequest();
http.open("GET", location.href+"?shout="+encodeURIComponent(document.getElementById("Shout").value)+"&name="+encodeURIComponent(document.getElementById("username").value), true);
http.send();
ShoutTime = <?php echo $shoutWait;?>+1;
ShoutWait();
unidle();
document.getElementById("Shout").value='';
}
else
{
ShoutWaitNote();
getLogs();
}
return false;
}
</script>
然后在页面上,我可以像$_GET["out"]一样放入数据库。。。等
现在,有没有一种更好的方法可以使用ajax向mysql数据库发送呐喊,而不需要在url中将呐喊作为GET?
我怀疑这里还有更大的问题,但您可以使用XMLHttpRequest进行POST,如下所示:
var http = new XMLHttpRequest();
http.open("POST", location.href);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.send("shout=something&name=something");
与GET版本相反:
var http = new XMLHttpRequest();
http.open("GET", location.href + "?shout=something&name=something");
http.send();
在这两种情况下,您都需要应用URL编码。祝你好运
相关文章:
- 在IntelliJ IDEA中,如何将JS文件从“;查找用法“;使用TypeScript时的结果
- Intellij idea远程调试javascript
- IDEA+Grunt-如何实时编辑JavaScript
- IntelliJ IDEA 2016.1 JavaScript调试器错误
- IntelliJ IDEA:json文件语法
- Intellij IDEA riot.js javascript风格支持
- 从IntelliJ IDEA的代码完成中排除javascript库
- IDEA 无法加载资源
- Intellij IDEA 12.1.7 JavaScript 文件在应用程序运行时不更新
- 为什么我在Intellij IDEA 11中调试nodejs应用程序失败
- Web Shoutbox Idea
- IntelliJ IDEA节点Webkit调试不起作用
- Intellij Idea多行变量的javascript格式
- Intellij IDEA,在编辑器中运行Javascript代码
- 包括JavaScript库到IntelliJ IDEA's自动完成
- JavaScript Singleton and IntelliJ Idea
- 在Intellij Idea中启用Ext.js的JSHint支持
- 在IntelliJ IDEA中,我如何创建一个键绑定,以当前文件作为参数执行shell脚本
- Jquery shoutbox IE error
- Using <noscript> within <head>: Good idea or bad