繁体   English   中英

在JOOMLA接收ajax电话?

[英]receiving ajax call in JOOMLA?

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

第一个JOOMLA本地语句不能正常工作。 我也试过get()getVar()。 不工作 它返回null

  $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);

尝试这个,

          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作为参数传递给控制器​​,然后它是如何到达那里的?

希望它的帮助..

我认为getCmd方法是导致问题的原因。 你可以在这里阅读更多JInput::get()

我建议你使用:

$app->input->getArray($_POST);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM