Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery ajax url参数drupal服务器_Jquery_Ajax_Web Services_Drupal - Fatal编程技术网

jQuery ajax url参数drupal服务器

jQuery ajax url参数drupal服务器,jquery,ajax,web-services,drupal,Jquery,Ajax,Web Services,Drupal,我正在尝试将内联参数发送到rest服务器: 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_

我正在尝试将内联参数发送到rest服务器:

  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),我定义了以下钩子服务资源:

  $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,
      ),
    ),
  );
试试这个:

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

jQuery.post(this.apiPath + '/disp', {'disp_id':  disp_id}, callback);
感谢Madbreaks(+1),移动到RESTful URL(请参阅和):

所以现在在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!");
    });
  });
});
感谢Madbreaks(+1),移动到RESTful URL(请参阅和):

所以现在在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!");
    });
  });
});

如果是REST服务器,我建议使用RESTfulUrlsGreat!是的,这让我重新思考。。。我要看看GET是否可行如果它是REST服务器,我建议使用RESTful URLsGreat!是的,这让我重新思考。。。我要看看GET是否可能名称结果:错误401和参数没有设置为参数,就像POST数据一样结果:错误401和参数没有设置为参数,就像POST数据一样