[英]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
作为参数传递给控制器,然后它是如何到达那里的?
希望它的帮助..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.