我希望能够完成我在PHP中使用AJAX完成AJAX所做的同样的事情。这可能吗?完成和AJAX一样只使用PHP
例如,请考虑下面的代码:
$.ajax({
async: false,
url: "/path/to/script/script.php",
type: "post",
data: {
'arg1':'arg_val',
'oper':'get_data',
'arg2':'arg_val_2',
'id_number':'223'
},
dataType: 'json',
success: function(data){
est_data = data[0];
},
error: function(jqXHR, textStatus, errorThrown){
return jqXHR['responseText'];
}
});
PHP内我想做同样的事情:通过几个职位变量的script.php
,并使其返回字符串响应,这是我在得到success
函数在上面的代码中。
我做了一些研究,我想我应该能够做到这一点使用http_post_fields,但我得到这样的响应:
HTTP/1.1 200 OK日期:星期三,2012年9月19日15:42: 01 GMT服务器:Apache/2.2.20(Ubuntu)X- Powered By:PHP/5.3.6-13ubuntu3.9 Set-Cookie: 53f143479d91e79747661fcf2777a0fa = 5kidtm7rcdn14o33amljgg8922; path =/ Vary:Accept-Encoding Content-Length:15 Content-Type:text/html not authorized。
任何人都知道如何做到这一点?
谢谢!
确保您发送的内容类型为文本/ JSON –
从你得到的回应来看,(“未授权”的结尾),它看起来像有一些授权步骤你错过了。有没有一个会议或什么? – Crontab