If I want to make a controller call like this:
name.php?data={"user":"test","pass":"test"}
To retrieve the necessary information using .ajax, I need assistance in configuring the variable to be sent in that specific format.
I previously used the following code:
var arr = [{
data: {
"user" : $("#usuario").val(),
"pass" : $("#password").val()
}];
arr = JSON.stringify(arr);
However, it does not produce the correct output. I've been advised to send the variable with the json included in it.
function callAjax(url, arr) {
var response = null;
jQuery.ajax({
url: url,
type: 'POST',
data: arr,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
async: false,
success: function(data) {
response = data;
},
error: function(jqXHR, textStatus, errorThrown) {
response = errorThrown;
},
timeout: 5000
});
return response;
}
Any suggestions?
Warm Regards!