doueta6642 2013-11-19 15:16 采纳率: 0%
浏览 133
已采纳

Symfony ajax响应但带标题:HTTP / 1.0 200 OK Cache-Control:no-cache Date

i'm in troubles with Symfony and an ajax call.

I'm in Local server on Windows 8 with XAMPP 1.8.2.

Every works good, but when i take response i have this, below the right text:

HTTP/1.0 200 OK Cache-Control: no-cache Date: Tue, 19 Nov 2013 14:58:18

Why?

My codes:

In HTML (Twig) at the bottom:

$.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>');
     }
});

Controller "score":

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);
    }
}

Where I make error?

  • 写回答

2条回答 默认 最新

  • dsg41888 2013-11-20 12:41
    关注

    I found the solution to my big problem:

    ->getContent() at the end of $points = self::pointsAction($id);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮