Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将PHP值数组传递给JQuery脚本_Javascript_Php_Jquery_Wordpress - Fatal编程技术网

Javascript 将PHP值数组传递给JQuery脚本

Javascript 将PHP值数组传递给JQuery脚本,javascript,php,jquery,wordpress,Javascript,Php,Jquery,Wordpress,我不知道这是否可能,但我觉得这是值得一问的。基本上,我需要将一系列值从php网页传递到底层JQuery 数组包含数据库中所有用户的列表,我想用这些用户填充一个下拉列表 这是我的php页面:带有html 如果有人对如何进行此操作有任何建议,我将不胜感激如果这些用户在下拉列表中,他们就可以访问jQuery代码。我很困惑-如果您已经从PHP获得填充的下拉列表,为什么要用jQuery填充下拉列表?您应该认真考虑使用自动完成而不是下拉列表。@MarcinWolny,下拉列表是使用Wordpress函数创建

我不知道这是否可能,但我觉得这是值得一问的。基本上,我需要将一系列值从php网页传递到底层JQuery

数组包含数据库中所有用户的列表,我想用这些用户填充一个下拉列表

这是我的php页面:带有html


如果有人对如何进行此操作有任何建议,我将不胜感激

如果这些用户在下拉列表中,他们就可以访问jQuery代码。我很困惑-如果您已经从PHP获得填充的下拉列表,为什么要用jQuery填充下拉列表?您应该认真考虑使用自动完成而不是下拉列表。@MarcinWolny,下拉列表是使用Wordpress函数创建的。它创建了一个下拉列表,我希望这个下拉列表显示在表的某些行上,而不是所有行上。我在Jquery中检查一个条件以启用此功能
<form action="<?the_permalink()?>" method="post">
    <div id="summary">
     <?php wp_dropdown_users(array('name' => 'CMP Member') ); ?> 
    <table id="ordertable">
        <tr><th>Product</th>
        <th>Quantity</th>
        <th>Bulk</th>
        <th>Options</th>
        </tr>
    </table>
    <!-- Comments Box -->
    Comments<br/>
    <textarea name="comments"></textarea><br/>
    <input name="product_list" id="products_field" type="hidden" value="<?= isset($_POST['product_list'])?$_POST['product_list']:'' ?>">
    Next Day Delivery <input type="checkbox" name="next-day-delivery" value="yes" />
    <input type="submit" value="Confirm Order" class="confirmBtn"/>
    </div>
    </form>
$this = $(this);

//If the cookie exists get a reference to the array it contains (productArray)
if($.cookie('order_cookie') != undefined){
    productArray = JSON.parse($.cookie('order_cookie'));
    $.cookie('order_cookie', JSON.stringify(productArray), { expires: 1, path: '/' });
    $('#products_field').val(encodeURIComponent($.cookie('order_cookie')));//Add to hidden field
}

//Reference to the order table
var ordertable = document.getElementById("ordertable");
//Loop through the Array and display in the table
for(var i = 0; i < productArray.length; i ++){
    //Check if a dropdown is required in bulk order...
    if(productArray[i].bulk == 'true'){
    var bulk = "<select><option value='...'>...</option></select>";
    }else{
    var bulk = "";
    }

    var productRow;
    productRow = '<tr>';
    productRow += '<td>' + productArray[i].stockCode + '</td>';
    productRow += '<td>' + productArray[i].quantity + '</td>';
    productRow += '<td>' + bulk + '</td>'; <-- Want to put dropdown here!
    productRow += '<td><input type="button" value="-" class="removeBtn"/>'
    productRow += '<input type="button" value="+" class="addBtn"/>'
    productRow += '<input type="button" value="Delete" class="deleteBtn"/></td>'
    productRow += '</tr>'
    $('#ordertable tr:last').after(productRow);
}