gin*_*lin 1 php ajax header http symfony
我遇到了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
Run Code Online (Sandbox Code Playgroud)
为什么?
我的代码:
在底部的HTML(Twig)中:
$.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>');
}
});
Run Code Online (Sandbox Code Playgroud)
控制器"得分":
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);
}
}
Run Code Online (Sandbox Code Playgroud)
我在哪里犯错误?
归档时间: |
|
查看次数: |
3940 次 |
最近记录: |