$.ajax({ url: "{:U('Index/wxBinding')}", type: 'post',dataType: 'json',
data: {'tel':tel,'password':password,'openid':"{$openid}",'headimg':"{$headimg}"},
success: function (d) { if (d.status ==='yes') {
layer.alert(d.msg, {skin: 'layui-layer-molv',closeBtn: 0});
window.location.href="{:U('Index/wxBind')}?bind=yes&tel="+tel; }
else layer.alert(d.msg, {skin: 'layui-layer-molv',closeBtn: 0}); } });
上面的写法php里面获取不到你想要的值,下面的才可以
var openid="{$openid}"; var headimg="{$headimg}";
$.ajax({ url: "{:U('Index/wxBinding')}", type: 'post',dataType: 'json',
data: {'tel':tel,'password':password,'openid':openid,'headimg':headimg},
success: function (d) { if (d.status ==='yes') {
layer.alert(d.msg, {skin: 'layui-layer-molv',closeBtn: 0});
window.location.href="{:U('Index/wxBind')}?bind=yes&tel="+tel; }
else layer.alert(d.msg, {skin: 'layui-layer-molv',closeBtn: 0}); } });
本文介绍了一种在Ajax调用中正确传递变量的方法,并对比了两种不同的实现方式,强调了直接赋值而非字符串拼接的重要性。
795

被折叠的 条评论
为什么被折叠?



