为什么$ .post方法不会将数据发送到PHP文件 [英] Why $.post method doesnt send the data to the PHP file

查看:81
本文介绍了为什么$ .post方法不会将数据发送到PHP文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将表单数据发送到php文件,然后使用$ .post方法将它们发送到我的数据库。以下是代码:

HTML:

I try to send the form data to php file, where they will be send to my database, with $.post method. Here is the code:
HTML:

<div id="chatlogs" class="hello" style="width: 200px; text-align: center">
		Loading Chats, Please Wait!!!
	</div>
<form method="post" name="form1" class= "mfo" action="">
	
<!--     <a href="#" name="set">Submit</a> -->
	<!-- <input type="button" name="set" value="SendMessage" onclick="submitChat()"> -->
	<table border="1" align="center">
	<tbody><tr>
	<td>Enter ChatName:</td> <td></td>
	</tr>
	<tr>
	<td><label for="msg">Message:</label></td> 
	<td><textarea name="msg"  style="width: 400px; height: 170px;"></textarea></td>
	</tr>
	<tr>
	<td colspan="2"><input name = "button" type = "Submit"

                              id = "update" value = "SendMessage" onclick="submitChat()">
    </td>
    </tr></tbody></table>
</form>





我是什么尝试过:



这是$ .post方法不起作用。我使用它是因为我不想要,当表单提交页面刷新时。





What I have tried:

This is the $.post method which doesn't work. I use it because I don't want, when form is submit page to refresh.

<script type="text/javascript">
		function submitChat(){
			if (form1.msg.value=="") {
				alert("All fields are required!!!");
				return;
			} 
		$.post("insert.php", {
			msg=form1.msg.value;
		}, function (e) {
			e.preventDefault;
		});
		}
		$(document).ready(function(e){
			$.ajaxSetup({cache:false});
			setInterval(function() {$('#chatlogs').load('logs.php');}, 1000);
    	});

	</script>

推荐答案

.post方法。以下是代码:

HTML:

.post method. Here is the code:
HTML:
<div id="chatlogs" class="hello" style="width: 200px; text-align: center">
		Loading Chats, Please Wait!!!
	</div>
<form method="post" name="form1" class= "mfo" action="">
	
<!--     <a href="#" name="set">Submit</a> -->
	<!-- <input type="button" name="set" value="SendMessage" onclick="submitChat()"> -->
	<table border="1" align="center">
	<tbody><tr>
	<td>Enter ChatName:</td> <td></td>
	</tr>
	<tr>
	<td><label for="msg">Message:</label></td> 
	<td><textarea name="msg"  style="width: 400px; height: 170px;"></textarea></td>
	</tr>
	<tr>
	<td colspan="2"><input name = "button" type = "Submit"

                              id = "update" value = "SendMessage" onclick="submitChat()">
    </td>
    </tr></tbody></table>
</form>





我是什么尝试过:



这是



What I have tried:

This is the


.post方法,它不起作用。我使用它是因为我不想要,当表单提交页面刷新时。



.post method which doesn't work. I use it because I don't want, when form is submit page to refresh.

<script type="text/javascript">
		function submitChat(){
			if (form1.msg.value=="") {
				alert("All fields are required!!!");
				return;
			}


.post( insert.php,{
msg = form1.msg.value;
}, function (e){
e.preventDefault;
});
}
.post("insert.php", { msg=form1.msg.value; }, function (e) { e.preventDefault; }); }


这篇关于为什么$ .post方法不会将数据发送到PHP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆