简体   繁体   English

如何获取ajax请求内容

[英]how to get ajax request content

In my symfony project, i try to get a ajax request content in a dump() to check datas. 在我的symfony项目中,我尝试在dump()中获取ajax请求内容以检查数据。 The objective is to processes this datas to do a sql request. 目的是处理此数据以执行sql请求。 In my controler when i do a dump, unfortunately I have not return?? 不幸的是,在我的控制者中进行转储时,我还没有回来?

this my js: 这是我的js:

eventResize: function(event) {
        console.log("eventResize : ok");
        var start1 = event.start.format("YYYY-MM-DD HH:mm:ss");
        var end1 = event.end.format("YYYY-MM-DD HH:mm:ss");
        var xhr = $.ajax({
            type: "POST",
            url: 'http://localhost/.../update',
            data: 'action=update&title=' + event.title + '&start=' + start1 + '&end=' + end1 + '&id=' + event.id,
            dataType: 'html',
            success: function(data) {
                console.log(data);
                window.location.reload(true);
            },
            error: function() {
                alert("error");
            },
        });
    },

and this my controler: 这是我的控制者:

public function updateEventAction(Request $request)
{
  if ($request->isXmlHttpRequest())
  {
      dump($request->request->get(''));die();
  }

}

Can anybody help me, please!!!??? 有人可以帮我吗!!!!!!

First, make sure you are making AJAX request to dev environment. 首先,请确保您正在向开发环境提出AJAX请求。

That die will stop symfony execution, so dump will never be printed. 该死将停止symfony的执行,因此转储将永远不会被打印。

You can debug it from profiler. 您可以从分析器中对其进行调试。

On the left menu of the profiler page you can get to see old requests by using the "Last 10" button. 在探查器页面的左侧菜单上,您可以使用“最后10个”按钮查看旧的请求。 Choose the request you'd like to see and there you should be able to see your dump at "debug" section. 选择您想看到的请求,然后您应该可以在“调试”部分看到转储。

also, take in mind that your code will fail because symfony controller must return a Response type ( return new Response() ) 另外,请记住您的代码将失败,因为symfony控制器必须返回Response类型( return new Response()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM