php如何接收對(duì)象數(shù)據(jù) php 接受post數(shù)據(jù)

php 怎么接收前端傳來(lái)的json數(shù)據(jù)

?php

成都創(chuàng)新互聯(lián)專(zhuān)注于河間企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站設(shè)計(jì),商城網(wǎng)站建設(shè)。河間網(wǎng)站建設(shè)公司,為河間等地區(qū)提供建站服務(wù)。全流程按需網(wǎng)站設(shè)計(jì),專(zhuān)業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,成都創(chuàng)新互聯(lián)專(zhuān)業(yè)和態(tài)度為您提供的服務(wù)

header("Content-type:text/html;charset=utf-8");

if($_POST){

$d = $_POST['data'];//這里獲取的直接就是數(shù)組了,不需要用到j(luò)son_decode

echo $d['doing'];

//print_r($d);

exit;

}

?

script src="js/jquery-1.7.2.min.js"/script

script type="text/javascript"

$(document).ready(function() {

$("#xx").click(function(){

var url = "test.php";

var str ="{'doing':'createvote','type':'type','num':'num','votetheme':'votetheme','creater':'loginname'}";//json格式字符串

var data = eval('('+str+')');//轉(zhuǎn)換成數(shù)組對(duì)象,不加這步,那么PHP獲取的是字符串。

$.post(url, {'data': data}, function(res) {//注意jquery的$.post的第2個(gè)參數(shù)必須是鍵值對(duì)形式

alert(res);

});

});

});

/script

input id="xx" type="button" value="點(diǎn)擊"

php如何接收js傳來(lái)的json對(duì)象

你無(wú)法傳json對(duì)象到服務(wù)端交互的,要傳的只是一個(gè)字符串(Json),是個(gè)字符串!

你發(fā)的代碼里是json的解析,沒(méi)有多大意義,你在php頁(yè)面這樣調(diào)試

var_dump($_REQUEST);//輸出所有數(shù)據(jù),如果存在的話,你會(huì)看到那個(gè)參數(shù)是啥

另外,json格式,主要方便javascript解析的,而不是php擅長(zhǎng)的內(nèi)容,多數(shù)情況下,是PHP返回json數(shù)據(jù)給js.

php的數(shù)組操作函數(shù)有主要的兩個(gè)json_encode()與json_decode();

從你的代碼中,我不確定你用何種方式通信,ajax?

我看你用到了jQuery,那里面有個(gè)ajax,方式類(lèi)似這樣的:

$.ajax({

type:?"post",???????//method;can?be?get?with?post?or?request

url:?"/mySever.php",//php?url

error:?function(){alert('Error');},

data:?{

data1:???name,

data2:???age,

},?

datatype:"json",//json?back

timeout:?5000,

success:?function(msg)

{

//eval(msg);//parase?here

}

});

return?false;

}

PHP怎么接收數(shù)據(jù)

三中接受方式:

$_GET ? ?//get過(guò)來(lái)的數(shù)據(jù)

$_POST ?//post過(guò)來(lái)的數(shù)據(jù)

file_get_contents("php://input") ? //接口過(guò)來(lái)的xml等字符串?dāng)?shù)據(jù)用這個(gè)接

這三個(gè)方法足以接受任何數(shù)據(jù)了,具體你還要百度一下用法

分享文章:php如何接收對(duì)象數(shù)據(jù) php 接受post數(shù)據(jù)
標(biāo)題網(wǎng)址:http://muchs.cn/article10/doeeego.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、網(wǎng)站內(nèi)鏈、動(dòng)態(tài)網(wǎng)站、定制網(wǎng)站、電子商務(wù)、ChatGPT

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)