Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.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
AJAX错误Drupal-7_Ajax_Drupal 7 - Fatal编程技术网

AJAX错误Drupal-7

AJAX错误Drupal-7,ajax,drupal-7,Ajax,Drupal 7,我正在创建一个模块,其中组合框之间存在依赖关系。有三个组合框:国家、州和地区。如果在“国家”组合框中选择“印度”,则“国家”组合框将包含印度的所有州,在“地区”的情况下也是如此 我已经使用AJAX实现了这一点。它在add form中正常工作,但当我要更新任何一个时,会发生以下错误: An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: /drupal/?q=system/aj

我正在创建一个模块,其中组合框之间存在依赖关系。有三个组合框:国家、州和地区。如果在“国家”组合框中选择“印度”,则“国家”组合框将包含印度的所有州,在“地区”的情况下也是如此

我已经使用AJAX实现了这一点。它在add form中正常工作,但当我要更新任何一个时,会发生以下错误:

An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /drupal/?q=system/ajax
StatusText: Service unavailable (with message)
ResponseText: PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'ajax' in 'where clause': SELECT district_name, country_id,state_id FROM {ajax_district} where id = ajax; Array
(
)
in edit_district_form() (line 291 of /home/mansmu/www/drupal/sites/default/modules/ajaxtest/ajaxtest.district.inc).
我的代码是:

////////////////////////////////////////////////////////
///////// FUNCTION FOR EDIT
////////////////////////////////////////////////////////
function edit_district_form($form, &$form_state) {
$request_url = request_uri();
// $request_id to get id of edit district.
$request_id = drupal_substr(strrchr($request_url, '/'), 1);

//// FOR country
$rows = array();
$result = db_query("SELECT id,country_name from {ajax_country} order by country_name");
while ($data = $result->fetchObject()) {
$id = $data->id;
$rows[$id] = $data->country_name;
}

//// FOR state
$state = array();
$result = db_query("SELECT id,state_name from {ajax_state} order by state_name");
while ($data = $result->fetchObject()) {
$id = $data->id;
$state[$id] = $data->state_name;
}

// $district_name varible to get name from database for a requested id.
$district_name = db_query("SELECT district_name, country_id,state_id FROM {ajax_district} where id = ".$request_id);
// Loop For show vehicle district name in text field to be update.
foreach ($district_name as $district) {*/
$form['values']['edit_country_name'] = array(
'#type' => 'select',
// '#default_value' => "{$district->country_id}",
'#required' => TRUE,
'#options' => $rows,
'#ajax' => array(
'effect' => 'fade',
'progress' => array('type' => 'none'),
'callback' => 'state_callback_edit',
'wrapper' => 'replace_edit_state',
),
);

$form['values']['edit_state_name'] = array(
'#type' => 'select',
// '#default_value' => "{$district->state_id}",
'#required' => TRUE,
'#options' => array(),
// The prefix/suffix provide the div that we're replacing, named by #ajax['wrapper'] above.
'#prefix' => '',
'#suffix' => '',
);

$form['values']['edit_district_name'] = array(
'#type' => 'textfield',
'#size' => 30,
//'#default_value' => "{$district->district_name}",
'#maxlength' => 80,
'#required' => TRUE,
);
}

$form['edit_district_submit'] = array(
'#type' => 'submit',
'#value' => t('Update'),
);
$form['actions']['cancel'] = array(
'#markup' => l(t('Cancel'), 'district'),
);

return $form;
}

您的代码行如下:

$request_id=drupal_substrstrstrrchr$request_url,'/',1

返回字符串“ajax”,使您的第三条SQL语句如下所示:

SELECT district_name, country_id,state_id FROM {ajax_district} where id = ajax;
很明显,“ajax”是错误的,我想你想要一个来自URL的值?您可以使用来提取它,这样就不需要运行drupal\u substr等

如果路径是ajax/12,则arg0将返回“ajax”,arg1将返回12,依此类推

希望有帮助

更新

如果需要在表单中保存请求ID,请在表单函数中执行以下操作:

$form['request_id'] = array('#type' => 'value', '#value' => $request_id);

然后,当您进入ajax回调时,您可以从$form\u state['values']['request\u id']或$form['request\u id']['value']获取它。

谢谢您的回复。是的,我希望url中有一个值,但当我调用ajax时,url是system/ajax或edit/12,其中12是要更新的我所在地区的id。我无法在ajax调用中发送此id,这就是我遇到的此类问题,
$form['request_id'] = array('#type' => 'value', '#value' => $request_id);