stateid的值没有传递给控制器

时间:2012-01-10 07:33:11

标签: codeigniter

在下面的脚本中,stateId的值未传递给控制器​​。任何人都能帮助我吗?

$("#ddlState").bind("change",function() {
    var stateId = $(this).val();
    $("#div_city_wrapper").load("page/new_city", {"stateId": stateId}, function(r) {
        alert('done loading'); 
    });
});

1 个答案:

答案 0 :(得分:0)

将额外的alert及其旁边的评论添加到您的JavaScript中:

$("#ddlState").bind("change",function()
{
   var stateId = $(this).val();

   alert(stateId); // if this isn't null or undefined, then the problem is in your controller

   $("#div_city_wrapper").load("page/new_city", {"stateId": stateId}, function(r) {
       alert('done loading'); 
    });
});

如果您的控制器出现问题,则需要将其添加为参数,例如

function new_city($stateId = NULL)
{
    if ($stateId === NULL)
    {
        // nothing was passed to the controller, so redirect somewhere or display an error
    }

    // the rest of your function...
}