Il mio codice Jquery è
jQuery(".loginbtn").click(function(e) {
var value = JSON.stringify(jQuery(jQuery('#form-login input[class!="noAjax"]'), jQuery('#form-login')).serialize());
alert(value); // here I am able to see "username=itsvalue&password&itsvalue...."
jQuery.ajax ({
type : "POST",
url : "index.php?option=com_ajax&module=socialauth&method=loginUser&format=json",
data : value,
contentType: "application/json",
success : function(response) {
jQuery("#login-msg").html(response['data']);
},
error : function(jqXHR, error, errorThrown) {
if(jqXHR.status){
jQuery("#login-msg").html(jqXHR.responseText + jqXHR.status);
}else{
alert("Something went wrong");
}
}
});
});
Ecco il mio PHP codice helper:
public static function loginUserAjax() {
// Required objects
$input = JFactory::getApplication()->input;
var_dump((new JInput($input->get('data', '', 'array')))->getString('username') );
}
qui non ricevo dati POST. Ho provato molte cose. Non so perché.
Non sono sicuro di $input->get('data', '', 'array')
. Sei sicuro che data
var sia passato?
Penso che puoi semplicemente usare $input->getString('username')
e così via per recuperare parti della query di dati passata.