0

我正在绑定两个不同的语句以在 JOOMLA 中获取 ajax 的 POST 结果

第一个 JOOMLA 本机语句无法正常工作。我也试过get()getVar()。. . 不工作。它返回空

  $vJson=$app->input->getCmd("chk");

但第二个没问题并显示结果

  $vJson = file_get_contents('php://input');

以下是客户端代码

         xmlhttpp.open("POST","index.php?option=com_hello&controller=SetComObjects",true);
                xmlhttpp.setRequestHeader("Content-Type", "application/json");
                xmlhttpp.onreadystatechange=function()
                {
                if (xmlhttpp.readyState==4 && xmlhttpp.status==200)
                  {
                  alert("haha");
                  }
                }
                 xmlhttpp.send(chk);  

我的控制器代码

 public function execute()
 {

  $app=JFactory::getApplication();


  //following line return null in str_json
  $str_json=$app->input->getCmd("chk");

  //$model->_buildQuery();

  //but following statement is  giving OK result
  $str_json = file_get_contents('php://input');


  $str_json=json_decode($str_json);
4

2 回答 2

1

尝试这个,

          var data = "chk="+chk;
          jQuery.ajax ({
            type: "POST",
            url: "index.php?option=com_hello&controller=SetComObjects?",
            data: data,
                    dataType: "json", 
            success: function(data) {


            var obj = jQuery.parseJSON(data);
                    alert( obj.name);//if its have a name
            }
         });

你没有将它chk作为参数传递给控制器​​,那么它是如何到达那里的?

希望它有帮助..

于 2013-10-15T08:38:23.870 回答
1

我认为 getCmd 方法是导致问题的原因。JInput::get() 您可以在此处阅读更多信息。

我建议你使用:

$app->input->getArray($_POST);
于 2013-10-15T09:38:13.910 回答