Home > Backend Development > PHP Tutorial > 求助,Jquery ajax在yii里的url问题,急

求助,Jquery ajax在yii里的url问题,急

WBOY
Release: 2016-06-23 14:27:40
Original
1064 people have browsed it

yii Jquery ajax url

我想传值到后台控制器方法里,但是怎么写url都不行

var data="name="+val;
//alert(data);error:function(){alert('错误');}

$.ajax({
type:'post',
url:"http://localhost/message/www/index.php?r=home/CkUser",

        data:data,
success:function(msg){
alert('msg');
$("#nameinfo").html(msg);

},


}
下面是action方法:
public function actionCkUser(){

//$name = $_POST['name'];

$name=Yii::app()->request->getParam('name');
echo $name.'bb';
$model=new User;
if($name)
{
  $model->username=$name;
      $user = User::model() -> find("username = '{$this -> username}'");
      $result='';
        if($user)
         {
       $result='用户已存在';
   echo '用户已存在';
     }
    else
     {
$result='ok';
echo 'ok';
 }
return $result;
}
Yii::app()->end();
$this->render('CkUser',array(
'model'=>$model,
));
}


回复讨论(解决方案)

打开这个地址看什么内容
http://localhost/message/www/index.php?r=home/CkUser

打开这个地址看什么内容
http://localhost/message/www/index.php?r=home/CkUser

是那个视图页面,显示bb

调试 ajax 时:
或者你完全按照框架提供的 ajax 操作进行
或者离开框架书写单独的服务端程序


打开这个地址看什么内容
http://localhost/message/www/index.php?r=home/CkUser

是那个视图页面,显示bb

$.ajax({
type:'post',
url:"http://localhost/message/www/index.php?r=home/CkUser",

        data:data,
success:function(msg){
alert('msg');
$("#nameinfo").html(msg);

},

});//这里少了括号

$(document).ready(function(){	data= 'name';	$.ajax({		type:'post',		url:"http://localhost/message/www/index.php?r=home/CkUser",						data:data,		success:function(msg){		alert('msg');		$("#nameinfo").html(msg);				},		});//这里少了括号	});
Copy after login

我那是粘贴少了,不是这问题

url:"?r=home/CkUser",


我那是粘贴少了,不是这问题
你用我这个代码 可以正常运行,难道是没有加载jquery? 

在firebug里运行一下不就知道这段代码那里出问题了。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template