Blo*_*und 6 javascript ajax jquery yii2
我遇到以下jquery代码的问题
$this->registerJs(
'jQuery(document).ready(function($){
$(".member").on("change",function(){
var id = $(this).attr("id");
// alert(id);
var n = $(this).val();
// alert(n);
$.post("'.\Yii::$app->getUrlManager()->createUrl(['death/stl_set_relation','id'=>'+id'])
.'&name="+id)
});
});'
);
Run Code Online (Sandbox Code Playgroud)
我希望ajax链接是这样的 http://192.168.1.4/~user/church/backend/web/death/stl_set_relation?id=20&name=1
但是我的代码我无法正确传递id的值.我的代码创建的是以下url
http://192.168.1.4/~user/church/backend/web/death/stl_set_relation?id=%2Bid&name=20
Run Code Online (Sandbox Code Playgroud)
我也尝试过这样
$.post("'.\Yii::$app->getUrlManager()->createUrl(['death/stl_set_relation','id'=>'"+id"'])
.'&name="+id)
Run Code Online (Sandbox Code Playgroud)
但它没有给我预期的结果
我怎样才能正确传递id的值?
我使用以下代码解决了问题
$.post("'.\Yii::$app->getUrlManager()->createUrl(['death/stl_set_relation'])
.'?id="+id+"&relation="+n)
Run Code Online (Sandbox Code Playgroud)