如何将表单字段参数传递给 CakePHP Ajax Helper 函数
我在 CakePHP 项目中完成了一些 jQuery 函数,但最后我决定尝试 Ajax Helper。不幸的是,我不知道如何将参数(表单字段值)传递给 AJAX 函数。我执行了以下操作:
$obtainProduct = $ajax->remoteFunction(
array(
'url' => array( 'controller' => 'products', 'action' => 'obtain', '{$OrderProductId->id}'),
'update' => 'post' )
);
...
echo $form->input('product_id', array('empty' => true, 'onchange' => "$obtainProduct"));
它调用该函数,但没有检索我需要的参数。
我从 API 链接文档 -api.cakephp.org/class/ajax-helper 中得到了这个想法,我想从选择框中获取 ID,获取它的值并在后端进行一些查找。
那么我如何使用助手获得 ('#OrderProductId option:selected').val 或类似的东西?
I've done some jQuery functions in a CakePHP project but finally I decided to try the Ajax Helper . Unfortunately I don't get the idea of how to pass a parameter (form field value) to the AJAX function. I did the following:
$obtainProduct = $ajax->remoteFunction(
array(
'url' => array( 'controller' => 'products', 'action' => 'obtain', '{$OrderProductId->id}'),
'update' => 'post' )
);
...
echo $form->input('product_id', array('empty' => true, 'onchange' => "$obtainProduct"));
It calls the function but without retrieving the parameter I need.
I got the idea from the API link docs -api.cakephp.org/class/ajax-helper and I want to get the ID from select box, get it's value and do some lookup in the backend.
So how can I get the ('#OrderProductId option:selected').val or something like this with the helper?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在cake php中你必须使用observe field
我假设您正在尝试填充选择框结果,
create( 'Product' ); ?>
input( 'product_id', array( 'empty' => true,'options'=>$defaultoptions) ) ?>
end('submit');?>
observeField( 'ProductProductid',
array(
'url' => array( 'controller'=>'products','action' => 'obtain' ),
'update' => 'PostProductid',
)
);
?>
这就是 php 代码,我假设您知道如何编写方法和视图来获取选择框结果。
如果有问题请告诉我。
in cake php you have to use observe field
i am assuming you are trying to populate a select box results
create( 'Product' ); ?>
input( 'product_id', array( 'empty' => true,'options'=>$defaultoptions) ) ?>
end('submit');?>
observeField( 'ProductProductid',
array(
'url' => array( 'controller'=>'products','action' => 'obtain' ),
'update' => 'PostProductid',
)
);
?>
Thats the php code i assume you know how to write the method and view to get the select box result.
if having problem let me know.