Reputation: 585
i am tying two different statements to get POST result of ajax in JOOMLA
first JOOMLA native statement is not working fine. i also tried get() getVar(). . . not working. it returns null
$vJson=$app->input->getCmd("chk");
but second one is OK and showing results
$vJson = file_get_contents('php://input');
following is client side code
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);
my controller code
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);
Upvotes: 0
Views: 539
Reputation: 8282
Try this,
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
}
});
Your are not passing the chk
to the controller as a parameter then how its gets there ?
Hope its helps..
Upvotes: 1