jquery
  • ajax
  • web-services
  • drupal
  • 2012-03-09 22 views 2 likes 
    2

    私は残りのサーバーにインラインパラメータを送信しようとしている:jQueryのAjaxのURLパラメータDrupalのサーバー

    jQuery.ajax({ 
        type: "POST", 
        url: this.apiPath + '/disp', 
        dataType: 'json', 
        data: 'disp_id=' + disp_id, 
        success: callback 
        }); 
    

    は、jQueryのAJAXにパラメータを渡す方法はありますか? 私は...マナーの多くが、決して試みた常に同じ答え

    data: {disp_id: disp_id}, 
    data: "{disp_id:" + '"' + disp_id + '"}', 
    data: JSON.stringify({disp_id: disp_id}), 
    

    :「401権限:行方不明に必要な引数disp_id」。

    jQuery.ajax({ 
        type: "POST", 
        url: this.apiPath + '/disp?disp_id=' + disp_id, 
        dataType: 'json', 
        success: callback 
        }); 
    

    エクストラ詳細:私が定義したサーバー側で

    this.apiPath = http://localhost/public_html/svc/disps

    (drupalの)

    私はこれを達成する唯一の方法はですhook_services_resourcesに続いて:

    $services_resources['disps']['actions']['disp'] = array(
        'help'     => t('Retrieves the cue of objects for a given id'), 
        'file'     => array('type' => 'inc', 'module' => 'disps', 'name' => 'resources/disps.resource',), 
        'callback'    => '_disps_resource_dispositivos', 
        'access callback'   => 'disps_can_view_disp', 
        'access arguments'  => array(NULL), 
        'access arguments append' => FALSE, 
        'args'     => array(
         array(
         'name'   => 'disp_id', 
         'type'   => 'string', 
         'description' => '', 
         'source'  => array('param' => 'disp_id',), 
         'optional'  => FALSE, 
        ), 
        ), 
    ); 
    
    +2

    RESTサーバーの場合は、RESTfulなURLを使用することをおすすめします – Madbreaks

    +0

    素晴らしい!はい、それは私に考えさせました...私はGETで可能かどうかを確認しようとしています – Miquel

    答えて

    0

    おかげで(そのための1)、(What are the best/common RESTful url verbs and actions?How to create REST URLs without verbs?を参照)RESTfulなURLへ移動:

    $services_resources['user']['relationships']['disps'] = array(
        'help'     => t('Retrieves the disps for a given user'), 
        'file'     => array('type' => 'inc', 'module' => 'disps', 'name' => 'resources/disps.resource',), 
        'callback'    => '_disps_user_dispositivos', 
        'access callback'   => '_disps_user_dispositivos_access', 
        'access callback file' => array('type' => 'inc', 'module' => 'disps', 'name' => 'resources/disps.resource',), 
        'access arguments'  => array('view'), 
        'access arguments append' => TRUE, 
        'args'     => array(
         array(
         'name'   => 'account', 
         'type'   => 'string', 
         'description' => 'The account to retrieve the cue from', 
         'source'  => array('path' => 0,), 
         'optional'  => FALSE, 
        ), 
         array(
         'name'   => 'disp_id', 
         'type'   => 'string', 
         'description' => 'The disp_id to retrieve the cue from', 
         'source'  => array('param' => 'disp_id',), 
         'optional'  => FALSE, 
        ), 
        ), 
    ); 
    

    ので、今のjsに

    userAPI.disps_cue= function (disp_id, user, callback) { 
        jQuery.ajax({ 
        type: "GET", 
        url: this.apiPath + 'user/' + user + '/disps', 
        dataType: 'json', 
        data: {disp_id: disp_id,}, 
        success: callback, 
        }); 
    } 
    
    jQuery(document).ready(function($) { 
        jQuery("#getCue").submit(function() { 
        jQuery("#msg").html("Enviando datos...")); 
        userAPI.disps_cue(jQuery("input:[name=disp_id]").val(), function(data) { 
         jQuery("#result").append(CreateTableView(data, "box-table-b")); 
         jQuery("#msg").html("Ok!"); 
        }); 
        }); 
    }); 
    
    があります
    0

    これを試してみてください:Madbreaksへ

    jQuery.post(this.apiPath + '/disp', {'disp_id':  disp_id}, callback); 
    
    +0

    同じ結果:エラー401とparametresはPOSTデータと同様にパラメータとして設定されていません – Miquel

    関連する問題