来自php变量的jQuery post

来自php变量的jQuery post,php,jquery-plugins,Php,Jquery Plugins,我正在创建一个“拖放”排序列表,我为一个现有的列表获取了一些代码,我需要修改它以满足我的需要。但是,为了正确地修改代码,我并不完全理解代码到底在做什么 基本上,我有一个php变量“$draft_id”,需要将它传递到我的updateList.php。如果我只是在updateList.php中定义$draft\u id=0,它可以正常工作,但我需要能够传入这个值 代码如下所示: (index.php) $(文档).ready(函数(){ 函数滑出(){ setTimeout(函数(){ $(“#

我正在创建一个“拖放”排序列表,我为一个现有的列表获取了一些代码,我需要修改它以满足我的需要。但是,为了正确地修改代码,我并不完全理解代码到底在做什么

基本上,我有一个php变量“$draft_id”,需要将它传递到我的
updateList.php
。如果我只是在
updateList.php
中定义
$draft\u id=0
,它可以正常工作,但我需要能够传入这个值

代码如下所示:

(index.php)


$(文档).ready(函数(){
函数滑出(){
setTimeout(函数(){
$(“#response”).slideUp(“slow”,function(){});
}, 2000);}
$(“#响应”).hide();
$(函数(){
$(“#list ul”).sortable({opacity:0.8,光标:'move',update:function(){
var order=$(this).sortable(“序列化”)+'&update=update';
$.post(“updateList.php”),顺序,函数(响应){
$(“#响应”).html(响应);
$(“#响应”).slideDown('slow');
滑出();
});
}
});
});
});
...

因此,基本上在‘updateList.php’中,我希望‘draft_id’取自$_POST数组,但我不确定如何正确传递它。任何帮助都将不胜感激。

经过一些研究,我已经找到了如何传递这个消息的方法,所以我想我会与大家分享,以防将来有人需要它。因此,我的主要问题是,我不完全理解$\u POST数组是如何设置的

在Javascript中有一个$.post,它使用一个在上面定义的变量'order'。这是传递$\u POST数组的地方。因此,通过添加附加条件,您可以在$\u POST数组中传递附加变量

所以我改变了:

<script type="text/javascript">
$(document).ready(function(){
function slideout(){
  setTimeout(function(){
    $("#response").slideUp("slow", function () {});
}, 2000);}
$("#response").hide();
$(function() {
    $("#list ul").sortable({ opacity: 0.8, cursor: 'move', update:function() {
        var order = $(this).sortable("serialize") + '&update=update';
        $.post("updateList.php", order, function(theResponse){
            $("#response").html(theResponse);
            $("#response").slideDown('slow');
            slideout();
        });
    }
  });
  });
});
</script>

$(文档).ready(函数(){
函数滑出(){
setTimeout(函数(){
$(“#response”).slideUp(“slow”,function(){});
}, 2000);}
$(“#响应”).hide();
$(函数(){
$(“#list ul”).sortable({opacity:0.8,光标:'move',update:function(){
var order=$(this).sortable(“序列化”)+'&update=update';
$.post(“updateList.php”),顺序,函数(响应){
$(“#响应”).html(响应);
$(“#响应”).slideDown('slow');
滑出();
});
}
});
});
});
致:


$(文档).ready(函数(){
函数滑出(){
setTimeout(函数(){
$(“#response”).slideUp(“slow”,function(){});
}, 2000);}
$(“#响应”).hide();
$(函数(){
$(“#list ul”).sortable({opacity:0.8,光标:'move',update:function(){
//我们将把&draft_id='php变量$draft_id'添加到order变量'
var order=$(this).sortable(“序列化”)+'&update=update'+'&draft_id=';
$.post(“updateList.php”),顺序,函数(响应){
$(“#响应”).html(响应);
$(“#响应”).slideDown('slow');
滑出();
});
}
});
});
});
这解决了我的问题,希望这能帮助将来遇到同样问题的人

<?php 
include("connect.php");
$array  = $_POST['arrayorder'];
if ($_POST['update'] == "update"){
     $count = 1;
        //------------------------------------
        $draft_id=$_POST['draft_id'];
        //------------------------------------
        foreach ($array as $idval) {
        $query = "UPDATE sort SET listorder = " . $count . " WHERE id = " . $idval . " AND draft_id=" . $draft_id;
        mysql_query($query) or die('Error, insert query failed');
        $count ++;  
    }
    echo 'Draft Order Saved!';
    }
?>
<script type="text/javascript">
$(document).ready(function(){
function slideout(){
  setTimeout(function(){
    $("#response").slideUp("slow", function () {});
}, 2000);}
$("#response").hide();
$(function() {
    $("#list ul").sortable({ opacity: 0.8, cursor: 'move', update:function() {
        var order = $(this).sortable("serialize") + '&update=update';
        $.post("updateList.php", order, function(theResponse){
            $("#response").html(theResponse);
            $("#response").slideDown('slow');
            slideout();
        });
    }
  });
  });
});
</script>
<?php   //this will later be pulled from another page, but for now
$draft_id='0';  //I just set it up for testing purposes.
$_POST['draft_id']=$draft_id;
?>
<script type="text/javascript">
$(document).ready(function(){
function slideout(){
  setTimeout(function(){
    $("#response").slideUp("slow", function () {});
}, 2000);}
$("#response").hide();
$(function() {
    $("#list ul").sortable({ opacity: 0.8, cursor: 'move', update:function() {

    //we will add &draft_id='the php variable $draft_id to the order variable'

        var order = $(this).sortable("serialize") + '&update=update' + '&draft_id=<?php echo $draft_id; ?>';
        $.post("updateList.php", order, function(theResponse){
            $("#response").html(theResponse);
            $("#response").slideDown('slow');
            slideout();
        });
    }
  });
  });
});
</script>