Ajax调用导致错误[object Object]

时间:2014-06-20 13:17:04

标签: php jquery ajax error-handling jquery-selectors

我在尝试通过ajax调用传递值时收到错误[object Object]。我正在使用jquery选择器来获取复选框的值。并试图通过ajax传递它,以便我只能获得我选择的复选框值。但是得到一个错误。谢谢。 这是我的代码:

dashboard.php

if($param['aktion'] == 'save-widget-vehicle')
{
    $page['register-fahrzeuge'] = array(
        1   => array( 'Fahrzeug','aktiv',$page['script'],''),
        0   => array( 'Edit-Fahrzeug','enabled',$page['script'],'',''), 
    );

        $opts = !empty($param['filterOpts']) ? $param['filterOpts'] : array();

      $tmp = array();
      foreach ($opts as $opt) {
            $tmp[] = '"'.$opt.'"';
      }
             $query = 
          'SELECT Fahrzeuge.dsnr,name
           FROM Fahrzeuge
           INNER JOIN ohne_fahrzeuge ON Fahrzeuge.dsnr = ohne_fahrzeuge.dsnr
           WHERE Fahrzeuge.name IN ('.implode(",", $tmp).')';

      $result = mysql_query($query, $myConnection);
      $data = array();
        $html = '<table width="538" cellspacing="0" cellpadding="0" border="0">
                <tr>
                    <td>
                        <div>'.CreateRegister($page['register-news']).'</div>
                        '.CreateMessage().'
                        <div class="cont-liste-verlauf register"> ';
                        while($row = mysql_fetch_array($result)){       
                        //$news_result = $fahrzeuge['name']; 
                        $html .= '<table id="fahrzeuge"> 
                                        <tr>
                                    <td>                                        
                                            <a href="amo_fahrzeuge.php"> '. $data[] = $row .'</a>                                       
                                </td>                               
                            </tr> ';                                
                              }

                        $html .= '</table>          
                    </div>
                </td>
            </tr>
        </table>';


                    $return = array(
            'status' => 1,
            'html'  => $html
        );

    echo json_encode($return);
    die();

      $param['aktion'] = 'get-widget-vehicle';
}

dashboard.js

function getFahrzeuge() {   
    var opts = [];
    $("input[type=checkbox]").each(function () {
     if (this.checked) {
         opts.push($(this).attr("id"));
     }
    }); 
    return opts;
 }


    function saveFahrzeugeWidget(opts){
        if(!opts || !opts.length){
          opts = allFahrzeuge;
        }

        $.ajax({
          type: "POST",
          url: "ajax/dashboard.php",
          dataType : 'json',
          cache: false,
          data: {filterOpts: opts, 'aktion' : 'save-widget-vehicle'},
          success: function(data){
           // $('#fahrzeuge').html(makeTable(records));
             $('#fahrzeuge').html(data.html);
          },
      error: function(data){
                alert('error' + data);
          }
        });
      }


      $('#fahrzeuge .butt-rahmen').live('click', function(){
            if($(this).attr('id') == 'submitId')
            var opts = getFahrzeuge();
            saveFahrzeugeWidget(opts);


 });
      var allFahrzeuge = [];
      $("input[type=checkbox]").each(function(){
        allFahrzeuge.push($(this)[0].id)
      }) 

0 个答案:

没有答案