php中ajax请求,在PHP中模拟jQuery.ajax请求
我必须在PHP中模拟AJAX请求,就像在jQuery中一样。我目前的代码在这里:原始AJAX调用(不得修改)$.ajax({type: "POST",url: "/someFile.php",data: data,success: function(response) {some_code_here;},error: function() {some_code_here;}});目前的PHP代码
我必须在PHP中模拟AJAX请求,就像在jQuery中一样。我目前的代码在这里:
原始AJAX调用(不得修改)
$.ajax({
type: "POST",
url: "/someFile.php",
data: data,
success: function(response) {
some_code_here;
},
error: function() {
some_code_here;
}
});目前的PHP代码 - 试图模拟上面JS的代码行为
function _misc_test() {
$data = json_decode("xxx"); // The "xxx" is placeholder for the same string, as is in data var in JS above
$ajaxResponse = _make_post_request('/someFile.php', $data);
print_r($ajaxResponse);
}
function _make_post_request($url, $data) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}不幸的是,PHP代码似乎并不像JS代码那样产生完全相同的数据包 - 这正是我所需要的。任何人都可以请我帮忙吗?
编辑:也许这很重要,JS中的data变量拥有像这样的复杂JS对象:
{"options":{"userIP":"89.102.122.16","playerType":"flash","playlistItems":[{"Type":"Archive","Format":"MP4_Web","Identifier":"209 452 80139\/0042","Title":"Nezn\u00e1m\u00ed hrdinov\u00e9","Region":"","SubtitlesUrl":"http:\/\/img2.ceskatelevize.cz\/ivysilani\/subtitles\/209\/209452801390042\/subtitles-1.txt","Indexes":null,"Gemius":{"Param":[{"Name":"materialIdentifier","Value":"209 452 80139\/0042"},{"Name":"testParam","Value":"testValue"}]}}],"previewImageURL":null}}
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐

所有评论(0)