chuanjie
chuanjie
  • 发布:2014-11-19 16:28
  • 更新:2015-01-04 12:04
  • 阅读:2637

post json数据,php端没有接收到数据

分类:HTML5+

var data={'username':'eeee'};
xhr=new plus.net.XMLHttpRequest();
xhr.onreadystatechange=xhrStatechange;
var url="user_api.php";
xhr.responseType="json";
xhr.open( "POST", url );

xhr.setRequestHeader('Content-Type','application/json');  
xhr.send(data);
2014-11-19 16:28 负责人:无 分享
已邀请:
DCloud_App_Array

DCloud_App_Array

确保服务器接收数据Content-Type支持'application/json'。

另外,xhr.responseType="json"是告诉xhr服务器返回的数据是json,而不是说提交的data是json。
send方法目前只支持String,send方法改成:

xhr.send(JSON.stringify(data));
  • chuanjie (作者)

    我那样做了,不行啊

    2014-11-19 17:00

aaaa

aaaa

把数据加到send里

该问题目前已经被锁定, 无法添加新回复