【问题标题】:How to pass value to controller?如何将值传递给控制器​​?
【发布时间】:2010-05-05 12:11:30
【问题描述】:

当我尝试将 url 值传递给控制器​​ action 时,action 没有获得所需的值。

我正在发送这样的值:

function value(url,id)
{
    alert(url);
    document.getElementById('rating').innerHTML=id;
    var params = 'artist='+id;
    alert(params);
    // var newurl='http://localhost/songs_full/public/eslresult/ratesong/userid/1/id/27';
    var myAjax = new Ajax.Request(newurl,{method: 'post',parameters:params,onComplete: loadResponse});        
    //var myAjax = new Ajax.Request(url,{method:'POST',parameters:params,onComplete: load});
    //alert(myAjax);

}

function load(http) 
{
    alert('success');
}

在我的控制器中:

public function ratesongAction()
{
    $user=$_POST['rating'];
    echo $user;
    $post= $this->getRequest()->getPost();
    //echo $post;
    $ratesongid= $this->_getParam('id');
}

但仍然没有得到结果。 我正在使用 zend 框架。

【问题讨论】:

  • 我是唯一一个花一分钟时间弄清楚什么是“通行证价值”的人吗? (相对于底部价值?)
  • @Pretzel LOL - 将“topass”修复为“to pass”
  • 看起来像这样使用 Zend Framework 作为后端,应该适当标记。

标签: php javascript html ajax


【解决方案1】:

这里需要更多信息...您如何调用这些函数?值是否在链中的任何阶段传递?你提到“action”,你到底指的是什么?

进一步说 - 如果您的意思是这些值没有在 PHP 部分中处理,您是否使用了正确命名的参数?我看到您的 Javascript 代码提到了一个名为“artist”的参数,但 PHP 代码只提到了“rating”。

【讨论】:

  • 我的操作代码是 public function ratesongAction() { print_r($_POST['artist']);回声$用户; $post= $this->getRequest()->getPost(); //回显 $post; $ratesongid= $this->_getParam('id'); //$ratesong= $post['艺术家']; // echo "ratesong".$ratesong; $lyrics = new Model_DbTable_Lyrics(); $result = $lyrics->getLyricsNameOnId($ratesongid); /*json 对象*/ $jason_result = Zend_Json::encode($result); $this->view->SongDetail = $jason_result; $this->_helper->layout->setLayout('layout');
  • 我的观点是 一星
  • 而js是函数值(url,id) { alert(url); document.getElementById('rating').innerHTML=id; var params = '艺术家='+id;警报(参数); var newurl='localhost/songs_full/public/eslresult/ratesong/userid'; var myAjax = new Ajax.Request(newurl,{method: 'post',parameters:params[0],onComplete: load}); //var myAjax = new Ajax.Request(url,{method:'POST',parameters:params,onComplete: load}); //警报(myAjax); } 函数加载(http){ 警报(“成功”); }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-08-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-10
相关资源
最近更新 更多