Home > Backend Development > PHP Tutorial > php中怎么接收Ajax POST数据

php中怎么接收Ajax POST数据

WBOY
Release: 2016-06-13 12:17:25
Original
2564 people have browsed it

php中如何接收Ajax POST数据

本帖最后由 u011547588 于 2015-04-04 19:01:44 编辑
<div class="dialog-comment-list-box"><br /><div class="loading-img"><table><tr><td><img src="tpl/default/img/loading.gif" alt="loading"><p>正在加载联系人</p></td></tr></table></div><br /><ul class="dialog-comment-list"><br /><!-- <li class="dialog-comment-list-item">what's going on?</li><br /><li class="dialog-comment-list-item reply">what's going on?</li><br /><li class="dialog-comment-list-item">what's this?</li><br /><li class="dialog-comment-list-item">what's this?</li><br /><li class="dialog-comment-list-item reply">???</li><br /><li class="dialog-comment-list-item"><img src="http://pic.yupoo.com/huang-yu/DFR1RRtM/small.jpg" alt="pic"></li> --><br /></ul><!-- /.dialog-comment-list --><br /></div><br /><div class="dialog-comment-edit"><br /><textarea name="" id="edit"></textarea><br /></div><!-- /.dialog-comment-edit --><br /><div class="site-im-dialog-footer"><br /><div class="for-post" data-toggle="popover" data-content="<small>写点什么再发吧!</small>"><br /><kbd><kbd>Ctrl</kbd>+<kbd>Enter</kbd></kbd><br /><button class="btn btn-success btn-sm" id="post-reply"><i class="fa fa-paper-plane"></i> 发送</button><br /></div><br /><br /></div><!-- /.site-im-dialog-footer --><br /></div>
Copy after login


<br />/**<br /> * 发送信息/获取信息<br /> */<br />// 清除定时器<br />function clearChatTimers(id){<br />	if(id){<br />		//请除指定用户定时执行<br />	    if(aPChatTimers[id]){<br />	    	clearTimeout(aPChatTimers[id]);<br />	    	loadFlag = false;<br />//	    	console.log('clear:'+aPChatTimers[id]);<br />		}<br />	}else{<br />		//请除所有用户定时执行<br />		for (var i=0;i<aPChatTimers.length;i++){<br />			if(aPChatTimers[i]){<br />				loadFlag = false;<br />		    	clearTimeout(aPChatTimers[i]);<br />//		    	console.log('clear:'+aPChatTimers[i]);<br />			}<br />		}<br />	}<br /><br />	<br />};<br />/*<br /><br />uid	<br /><br /><br />*/<br /><br /><br />/**<br /> * 返回接收者Id<br /> * @returns<br /> */<br />function getRecipientIdFromReplyBtn(){<br />	var uid = $.trim($("#post-reply").attr('data-send-uid'));<br />	if(uid == undefined||uid ==''){<br />		uid = false;<br />	}<br />	return uid;<br />}<br />/**<br /> * 清空发送的文本内容<br /> * @returns<br /> */<br />function clearInputMessage(){<br />	$("#edit").val('');<br />	$("#post-reply").focus();<br />}<br /><br />/**<br /> * 获取发送的文本内容<br /> * @returns<br /> */<br />function getInputMessage(){<br />	var  sMsg = $.trim($("#edit").val());<br />	if(sMsg == undefined||sMsg ==''){<br />		sMsg = false;<br />	}<br />	return sMsg;<br />}<br /><br />//发送信息<br /> function sendPrivateMessages(){<br />	 var uid,message;<br />		 uid = getRecipientIdFromReplyBtn();<br />		 message 	= getInputMessage();<br />	 <br />	 if(message === false){<br />	 	$('.for-post').popover('show');<br />		$("#edit").focus(function() {<br />			$('.for-post').popover('hide');<br />		});<br />		 return false;<br />	 }<br />	 <br /> 	 $("#post-reply").attr('disabled','disabled');<br />	 clearChatTimers(0);<br /><br />        //index.php?do=webim&action=send_messages    POST<br />	 <br />   	 $.post('index.php?do=webim',{action:'send_messages',uid:uid,sMessage:message}, function(json) {<br />   		 if(json.status == '1'){<br />   		 	if($('.dialog-comment-list').find('li').length >0){<br />   		 		var _scrollHeight = $('.dialog-comment-list').find('li').last().offset().top;<br />   		 		$("#post-reply").closest('.site-im-dialog').find('.dialog-comment-list').animate({zoom:1},function(){<br />		    		$(".dialog-comment-list-box").data('jsp').scrollTo(0, _scrollHeight);<br />		    	});<br />   		 	}<br /><br />    		 $("#post-reply").removeAttr('disabled');<br />    		 clearInputMessage();<br />    		 clearChatTimers(0);<br /> 		     getPrivateMessages(uid);<br />   		 }else{<br />   			 tipsOp(json.msg,'error');<br />   			 $("#post-reply").removeAttr('disabled');<br />   		 }<br />   		 	<br />     },'json');<br />}<br />
Copy after login



返回    {"msg":"\u53d1\u9001\u6210\u529f","status":"1","data":[]}

单击发送或 Ctrl+Enter 按钮不抬起 (如图)







如何才能单击发送按钮或者按CTRL+ENTER    把数据POST到php处理 求PHP代码





------解决思路----------------------
执行 $.post('index.php?do=webim',{action:'send_messages',uid:uid,sMessage:message} ... 后
php 得到
$_GET['do'] 为 webim
$_POST['action'] 为 send_messages
$_POST['uid'] 为 uid 的值
$_POST['sMessage'] 为 message 的值
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template