onunix
就是说,根据舰长的修改,并且在此基础上,把 return false 改成 return true,可以同时实现执行url和弹出提示框,现在我还希望,对这个新的url的访问是悄悄进行的,在地址栏不发生改变,因为让用户切换到一个新的页面,在我这种情况下,不合适,我原来想ajax就是解决这个问题的,所以才想用ajax。
根据舰长的修改后,发现也有点小问题, 使用
return false
,就不执行 url,当然也不跳转,改成return true
,就执行url,但是跳转了。(这句中的:'onclick'=>'alert("点击了我"); return false;'
,)多谢,现在既访问了url,又弹出了提示框,但是还有个问题:我发现在IE浏览器的地址栏上变成了新的url,然后跳转到了新的url的页面。其实,我用ajax是希望用这个新的url来执行一些事情,例如,把数据导出到文件,或者修改个什么东西,但是在地址栏不进行跳转。请问这个可以实现么?
对应的源文件
执行了对网址的访问,但点击无反应:<input href="http://localhost/Yii/index.php?r=Test/export" name="yt0" type="button" value="导出到文件" id="yt0" /><a onclick="alert("点击了我"); return false;" href="http://localhost/Yii/download/abc.csv">下载文件</a>
没有执行,点击有反应:
<input name="yt0" type="button" value="导出到文件" id="yt0" /><a onclick="alert("点击了我"); return false;" href="http://localhost/Yii/download/abc.csv">下载文件</a>
我怎么才能既执行对url的访问,又点击产生反应呢?
难道ajaxLink有这个bug?
return false改为return true,还是没有弹出“点击了我”的提示框。
去掉
array('type'=>'POST')
就会有反应,但是'http://localhost/Yii/index.php?r=Test/export'
不会执行,加上array('type'=>'POST')
, 则'http://localhost/Yii/index.php?r=Test/export'
会执行,但是点击没有反应。我既要有反应,又希望 则
'http://localhost/Yii/index.php?r=Test/export'
能执行,该如何修改?得到执行了,代码如下:
<?php echo CHtml::ajaxLink('GO', 'http://localhost/Yii/index.php?r=test/export', array('type'=>'POST'), //there are various other options for jquery ajax array('href'=>'http://localhost/Yii/index.php?r=test/export'));
但是怎么得到控制器中
actionexport()
的返回值呢(return的值)我写成这样子了:
在admin.php中加入
<script type=”text/javascript”> function ajaxupdate() { //url=”<?php echo Yii::app()->request->baseUrl;?>/index.php/site/”+url; var pars = ""; $.ajax({ type: “POST”,//以POST方法接收表单数据 url: “http://localhost/Yii/index.php?r=test/index”, data: pars, dataType : “php”, success: function(msg){ } </script> <?php echo CHtml::link('点我吧','#',array( 'onclick'=>'alert("点击了我"); ajaxupdate();alert("点击了我"); return false;', )); ?>
但还有点错误,谁能够帮我改改,使得
http://localhost/Yii/index.php?r=test/index
得到执行吗?