我遇到了symfony和ajax调用的麻烦。
我在windows 8上的本地服务器上,使用xampp 1.8.2。
每件事都很好,但当我回答时,我有一个问题,在正确的文本下面:
HTTP/1.0 200 OK Cache-Control: no-cache Date: Tue, 19 Nov 2013 14:58:18
为什么?
我的代码:
在底部的HTML(细枝)中:
$.ajax({
url: "{{ path('score') }}",
data: { id: scoreid, value: value },
dataType: 'json',
type: 'POST',
success: function (data) {
if(data.responseCode==200 ){
$('#score').html(data.score);
$('#score').css("color","green");
}
else if(data.responseCode==400){
$('#score').html(data.score);
$('#score').css("color","red");
}
else{
alert("An unexpeded error occured.");
$('#score').html(data);
}
},
error: function (jxhr, msg, err) {
$('#score').html('<span style="color:red">Error!</span>');
}
});
控制者“得分”:
class scoreController extends Controller
{
public function onepointAction(Request $request) {
....some logical...
$points = self::pointsAction($id);
$return=array("responseCode"=>200, "score"=>"Score: ".$num.".", "goal"=>"".$points);
}
else {
$return=array("responseCode"=>400, "score"=>"No good!");
}
$return = json_encode($return);
return new Response($return,200,array('Content-Type'=>'application/json'));
}
public function pointsAction($id) {
......some logical query... ended by:
->getQuery();
$pointsOk = $query->getResult();
$avgScore = $avgScore[0]["score_avg"];
$numScore = $avgPoints[0]["score_count"];
$points = ("Scores: ".$avgScore."Goals: ".$numScore);
return new Response($points);
}
}
我在哪里出错?
最佳答案
我找到了解决我大问题的办法:->getContent()
在$points结尾处=self::pointsAction($id);
关于php - Symfony ajax响应,但带有 header :HTTP/1.0 200 OK高速缓存控制:无高速缓存日期,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20075235/