伙计们,这是我用来发出 ajax 请求的代码,它不是完整的代码,只是相关的东西
<div class="container whiteFont">
<label>New Tag</label>
<?php echo $this->Form->input('tagValue'); ?>
<input id="tag-button" type="button" value="Add Tag"/>
<div id=tag></div>
<?php
//on button click sands request to controller and displays response data in chosen field
$this->Js->get('#tag-button')->event(
'click',
$this->Js->request(
array('controller' => 'tags', 'action' => 'add',(Here need help),$this->Form->value('Post.id')),
array(
'update' => '#tag',
'async' => true,
)
)
);
?>
现在的问题是,我的操作需要两个参数。 我可以设置第二个,即 Post.id 但我无法获取 id 为“tagValue”的文本字段的值。 我也尝试过只使用 html 输入字段。 当我尝试使用 Js->get here 时,它也不起作用。 请帮帮我。 谢谢
最佳答案
$this->Js->get('#tag-button')->event(
'click',
$this->Js->request(
array('controller' => 'tags', 'action' => 'add',(Here need help),$this->Form->value('Post.id')),
array(
'update' => '#tag',
'async' => true,
'dataExpression'=>true,
'data'=> $this->Js->serializeForm(array(
'Post.id' => 1
))
使用dataExpression和data来发送参数。
关于javascript - Cakephp Ajax,使用 Js Helper 获取文本字段的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20777020/