简体   繁体   中英

cant pass parameter from ajax to php

I have used Jquery UI to update my table position.And its running fine. But now i want to pass the parameter from ajax to php to update my database using the current table position. But i am getting $('#widget').html(data.html); typeerror:data=null . And not able to pass parameter from ajax to php.In firebug i can see the parameter are passing but why i am not able to use it into my php file dont know. I even try to echo update statement but its not echoing. Here is my code: Js code:

 $("#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 code:

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();
}

?>

In your $.ajax({ code block:

Instead of :

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

Try to use like:

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

Hope that helps ! Let me know if you have any problems !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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