javascript - 如何消除jquery错误

标签 javascript jquery

我想使用 jquery 在 php 页面中制作动态选择框,但是当我运行代码时它给了我两个错误 SyntaxError: 参数列表后缺少 ),firebug 在线显示此错误

jQuery.post("<? include(FORMKEY."/form_add_events.php"); ?>",function(data){

第二个错误是当我单击“添加事件”按钮时,它给出错误 ReferenceError: addRow 未定义,我如何删除这两个错误并在按钮单击时创建动态选择框,这是我的代码:

<script type="text/javascript">
    jQuery.noConflict();

    function addRow(btn) {
        jQuery.post("<? include(FORMKEY."/form_add_events.php"); ?>",function(data){
            $(btn).closest('table').append(data);
        });
    }
</script>

这是我的 form_add_events.php 代码:

 <?php
     $strQuery1="SELECT event_id,event_name from events";
     $result1 = $GLOBALS ['mysqli']->query ($strQuery1) or die ($GLOBALS ['mysqli']->error . __LINE__);
     echo '<tr><td><select>';
     while($ors1 = $result1->fetch_assoc()) {
         echo '<option value="'.$ors1['event_id'].'">'.$ors1['event_name'].'</option>';
     } 
     echo '</select></td></td>';
 ?>

这是我的 html 代码:

<table>
    <tr>
        <td>
            <button type="button" value="Add" onclick="addRow(this)">Add Events</button>
        </td>
    </tr>
</table>

最佳答案

我认为你的引用在这一行中是错误的。尝试在 PHP 字符串中使用单引号,这样它们就不会与 javasacript 的双引号冲突。另外,最佳实践是您使用

jQuery.post("<? include(FORMKEY.'/form_add_events.php'); ?>",function(data){

关于javascript - 如何消除jquery错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21480915/

相关文章:

javascript - 如何在嵌套数组中使用reducer

javascript - 在 chrome 扩展中使用 redux

javascript - 根据条件将单元格值从一张谷歌工作表复制到另一张谷歌工作表

java - 如何在Struts2中将JSP目标设置为父框架?

javascript - 用户当前时间

javascript - jQuery计算输入的剩余字符长度

javascript - 链接字体、CSS 和脚本的顺序是什么

jquery工具: Calling doc ready initialization in script loaded by ajax

jquery - 只能拖动可拖动元素一次

javascript - 更改 jQuery 加载代码