首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >调试Ajax回调

调试Ajax回调
EN

Drupal用户
提问于 2020-08-25 17:29:26
回答 1查看 1.2K关注 0票数 0

目标:打印/转储要调试的$formState

我正在修改一个表单,其功能起作用:

代码语言:javascript
复制
$form['elements']['location']['deparment']['#ajax'] = [
  'callback' => 'myAjaxCallback',
  'event' => 'change',
  'progress' => [
    'type' => 'throbber',
    'message' => t('Verifying entry...'),
  ]
];

但是我想要的是能够打印出$formState在myAjaxCallback中

代码语言:javascript
复制
function myAjaxCallback(array &$form, FormStateInterface $formState){
 $response = new AjaxResponse();
 print_r($formState); //I've tried, with memory_limit=-1 . it just hangs
 dump($formState); //gives me File upload exceeds. This comes from issue with using dump in ajax
                     https://drupal.stackexchange.com/questions/250078/ajax-submission-leads-to-an-unrecoverable-error-occurred-the-uploaded-file-l

 return $response
}

我还读过https://www.drupal.org/docs/drupal-apis/javascript-api/ajax-forms并尝试过调试AJAX回调函数,其中包括:

代码语言:javascript
复制
$response = new AjaxResponse();
$debugOut = @Kint::dump($formState); //but this uses dump too, which gives me ajax errors

所以dd($formState->getValues());有点工作。这就是它展示给我的。所以,正如你所看到的,我现在可以看到变量。这不是最好的,而是可读的。

然而,如果我去/webform?ajax_form=1,它甚至是不可读的。

为了能够调试变量$formState,我的想法已经用完了。

EN

回答 1

Drupal用户

回答已采纳

发布于 2020-08-27 00:38:41

@sonfd Xdebug帮助打印出漂亮的值。不再有print_r()或kint()错误。

票数 2
EN
页面原文内容由Drupal提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://drupal.stackexchange.com/questions/296278

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档