yii2 获取 ajax post数据库,Yii2 Ajax .post to controller from dropdownList of

I have a DropDown list. I've written the code but it's not working. Please help me to fix it:

echo $form->field($model, 'Adrop')->dropDownList(

[

'' => 'Please Choose',

'1' => 'item 1',

'2' => 'item 2'

],

[

'onchange' => '$.post(Yii::$app->urlManager->createUrl . "users/A_action"), function(data) {

$("#test_div").html(data)

}'

]

);

Also I want to send selected data, and don't know where to write it.

In the Controller I have this action

public function actionA_action() {

$data = "TTT";

return $data;

}

Now when I select something in the DropDown list, nothing happens in my test_div :(

UPDATE

Thanks to Mihai P. now I'm using this code

echo $form->field($model, 'Adrop')->dropDownList(

[''=>'Please Choose','1'=>'item 1','2'=>'item 2'],

[

'onchange'=>'$.post( "'.Yii::$app->urlManager->createUrl(["users/A_action"]).'",function(data){

$("#test_div").html( data )

}']);

?>

The HTML is formed in the following way

Please Choose

item 1

item 2

But when I choose something

in debug this string is highlighted

item 2

and there is one error saying

Uncaught SyntaxError: Unexpected token }

Final UPDATE

I've added one closing bracket on the last string of this code there are two of them closing now as you can see, and that was the problem. Semicolumn also will be a plus, but I've tested code works without it OK. problem was in closing bracket.

'onchange'=>'$.post( "'.Yii::$app->urlManager->createUrl(["users/A_action"]).'",function(data){

$("#test_div").html( data );

})']);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值