我正在开发一个将连接到站点API的移动应用程序。 我正在通过jQuery Ajax发送数据,但是在转义数据以实现URL友好时,我的GET参数在到达API时变为空。jQuery Ajax发送空的转义数据
我有以下的jQuery/JavaScript代码
var id =;
var token = 55fggt98ujhsbnh;
var email = "[email protected]";
var json = { // Create object
"task" : "request",
"id" : id,
"token" : token
};
var jsonfull = []; // Push to jsonfull.
jsonfull.push(json);
var url = JSON.stringify(json);
var crypt = '&hash='+CryptoJS.SHA512(token+task+email+url).toString(CryptoJS.enc.Hex)+'&callback=?';
var x = 'json='+escape(url)+escape(crypt);
$.ajax({
url: "mydemosite.com/?p=app&",
crossDomain: true,
data: x,
dataType: "jsonp"
})
.done(function (json){
alert(json.response);
});
在我的PHP代码,其中的数据被发送,我有下面的代码接收AJAX数据
$rest = $_GET['json'];
$api = json_decode($rest,true);
$type = 'json';
file_put_contents('logs/api_task.txt', print_r($_GET,true));
检查文件,其中的内容被保存我得到这个
Array
(
[p] => app
[callback] => jQuery1111006607784540392458_1446159115404
[json] => {"task":"balance","merchant":"hifee","token":"1446159118-5632a30e2ed0f5632a30e2ed465614257"}&hash=0b645fac1f3ef3b5911435e58fbc1f157bd0273a01a664427b014fb517d9c46ae60e1d2fe3128d76d610706f9b8a9ac660517b77cbf4c3c6e02e597b065d1038&callback=?
[_] => 1446159115406
)
我希望得到的数据是
Array
(
[p] => app
[callback] => jQuery1111006607784540392458_1446159115404
[json] => {"task":"balance","merchant":"hifee","token":"1446159118-5632a30e2ed0f5632a30e2ed465614257"}
[hash] => 0b645fac1f3ef3b5911435e58fbc1f157bd0273a01a664427b014fb517d9c46ae60e1d2fe3128d76d610706f9b8a9ac660517b77cbf4c3c6e02e597b065d1038
)
我希望能得到任何帮助。