Javascript 文本区域上的Symfony3 Ajax存在多行错误,但不存在单行错误

Javascript 文本区域上的Symfony3 Ajax存在多行错误,但不存在单行错误,javascript,ajax,textarea,symfony,Javascript,Ajax,Textarea,Symfony,我想用一些Ajax保存textarea的值 JS: 用细枝上的“replace(/\n/g,”)和“replace({'':'\n'})”解决。仍然不知道原因。不要使用GET请求更改数据。获取要缓存的请求。如果您更改数据,请始终使用POST或PUT请求。生成了什么错误?我将按您的方式尝试。问题是没有具体的错误,如果它有效的话,我会邀请你发布一个答案。 function saveCommentary(id) { commentary = document.getElementById('c

我想用一些Ajax保存textarea的值

JS:


用细枝上的“replace(/\n/g,”)和“replace({'':'\n'})”解决。仍然不知道原因。不要使用GET请求更改数据。获取要缓存的请求。如果您更改数据,请始终使用POST或PUT请求。生成了什么错误?我将按您的方式尝试。问题是没有具体的错误,如果它有效的话,我会邀请你发布一个答案。
function saveCommentary(id)
{
    commentary = document.getElementById('commentaire' + id).value.replace(/\n/g, '<br />');
    $.get(Routing.generate('ajax_savecommentary', { id:id, commentary:commentary }), 
    function(response)
    {
        alert('commentary');
        alert(commentary);
    }, "json");
}
public function saveCommentaryAction($id, $commentary)
{
    if (!$this->get('session')->get('compte'))
        return $this->redirect($this->generateUrl('accueil'));

    $request = $this->container->get('request_stack')->getCurrentRequest();
    $isAjax = $request->isXMLHttpRequest();

    if ($isAjax)
    {
        $information = $this->getDoctrine()->getManager()->getRepository('CommonBundle:Information')->find($id);
        $information->setCommentaire(nl2br($commentary));
        $this->getDoctrine()->getManager()->flush();

        $response = array("code" => 100, "success" => true, 'commentary' => $commentary);
        return new Response(json_encode($response));
    }
    $response = array("code" => 0, "success" => false, 'commentary' => $commentary);
    return new Response(json_encode($response));
}