繁体   English   中英

无法将参数从ajax传递到php

[英]cant pass parameter from ajax to php

我已经使用Jquery UI更新了我的表位置,并且运行良好。 但是现在我想将参数从ajax传递到php,以使用当前表位置更新数据库。 但是我正在获得$('#widget')。html(data.html); typeerror:data = null。 并且无法将参数从ajax传递到php.firebug中,我可以看到参数正在传递,但是为什么我无法将其用于我的php文件中却不知道。 我什至尝试回显更新语句,但不回显。 这是我的代码:Js代码:

 $("#widget_update").sortable({    

       update: function() {        

        var widget = $(this).sortable("serialize") + '&action=updatewidget';

        //var element_id1 = ui.item[0].id;
        //alert(element_id1);      

        $.ajax({
        type: "POST",
        url: "ajax/dashboard.php",
        dataType : 'json',
        cache: false,
        data: {'aktion' : 'show-widget','new_widget':widget},
        success: function(data){            
            $('#widget').html(data.html);                           
        },
        error: function(data){
            alert('Error');         
        }
        });
      }
}); 

php代码:

if($param['aktion'] == 'show-widget')
{   
    $page['button'] = array(
    1 => array( 'Add Widget','pfeil2r','',"'#'",'','','addwidgetId'),
    2 => array( 'Remove Widget','pfeil2r','',"'#'",'','','removewidgetId'), 
    );

    $action                 = mysql_real_escape_string($_POST['action']); 
    $updateRecordsArray     = $_POST['recordsArray'];
    print_r($action);

    if ($action == "updatewidget"){

      $position = 1;
      foreach ($updateRecordsArray as $widget_id) {     
    echo $sql="Update dashboard_widget_users inner join dashboard_widget on dashboard_widget_users.dsnr_dashboard_widget=dashboard_widget.ID
               set dashboard_widget_users.position=".$position." 
               where dashboard_widget.id=".$widget_id." 
               and dashboard_widget_users.dsnr_yw_user=10";                                                                              
         $sql_update=mysql_query($sql);     
         $position = $position + 1;     
        }
    }                                   
    $html= '<table width="538" cellspacing="0" cellpadding="0" border="0" >
                                        <tr>
                                            <td>
                                          <table id="widget">
                                                <td>

                                                </td>
                                            </table>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="2">
                                                '.CreateButton($page['button']).'
                                            </td>
                                        </tr>                                       
                                    </table>';                        
    $return = array(
            'status' => 1,
            'html'  => $html
        );

    echo json_encode($return);
    die();
}

?>

在您的$.ajax({代码块中:

代替 :

data: {'aktion' : 'show-widget','new_widget':widget},

尝试像这样使用:

data:'aktion=show-widget&new_widget='+widget,

希望有帮助! 让我知道您是否有任何问题!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM