【问题标题】:Jquery Onclick .post returns // Uncaught SyntaxError: '' string literal contains an unescaped line breakJquery Onclick .post 返回 // Uncaught SyntaxError: '' string literal contains an unscaped line break
【发布时间】:2021-03-23 03:49:30
【问题描述】:

我在 jquery 中有一个简单的点击/发布:

$(".login").click(function(){
  var txt = "1";
    $.post("content.php", {choiceregister: txt}, function(result){    
    $(".this").html(result);
    });
});

结果被添加到 .this

在 content.php 我有一个简单的 div,这个 div 是多行的。

echo '
<form method="post">
    <table>
        <tr>
            <td>
                E-mail:
            </td>
            <td>
                <input type="text" name="email">
            </td>
        </tr>
        <tr>
            <td>
                Password:
            </td>
            <td>
                <input type="password" name="password">
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit" value="Login">
            </td>
        </tr>
    </table>
</form>';

不知道为什么我得到这个 Uncaught SyntaxError: '' string literal contains an unscaped line break。应该足够简单。如果您有任何想法,将不胜感激。

【问题讨论】:

  • 什么simple div,我看到&lt;form&gt;?旁注:现在保存自己! ...避免使用表格作为表单布局!!
  • 替换所有空格即可。
  • @PaulT。您对 div 的看法是正确的……这是我的错。对于桌子,你也是对的。在div中会更好。 ;)

标签: php jquery


【解决方案1】:

在这里你收到 HTML 内容响应,你没有在你的 post 方法上声明,

如下提出您的要求

$.ajax({
      type: 'POST',
      url: "content.php",
      data: myKeyVals,
      dataType: "html", //here we mention the response data type
      success: function(result) { 
           $("replace your element selector").html(result); 
      }
});

希望它对你有用。

【讨论】:

    猜你喜欢
    • 2019-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多