What do you mean when you say getting empty request in controller. a 500 error code could mean many things. If the endpoint exists then simply console.log the response to see what's coming back. If you're not able to get that then check the endpoint actually exists. Eliminate the problems one by one.
Mar 27, 2023
8
Level 3
Getting Empty Request in Controller
Hello Everyone ! I am sending some specific data through ajax but getting empty request in controller and the error is "500 Server Error". this is my code:
$(document).on('click', '#status_update', function(e) {
var data = $(this).prop('checked') == true ? 1 : 0;
var firmware_id = $(this).data('id')
var url = "{{ route('changeStatus', '') }}/" + firmware_id;
Send_Ajax_Req_To_Server('GET', data, url, '', updatedStatus);
});
and My Generic function for AJAX is:
function Send_Ajax_Req_To_Server(requestType = 'GET', data, url, dataType = 'json', callBack = '') {
$.ajax({
type: requestType,
url: url,
data: data,
dataType: dataType,
processData: false,
contentType: false,
success: function(response) {
if (typeof callBack === 'function') {
callBack(response);
} else {
console.log('error');
}
},
error: function(response) {
if (typeof callBack === 'function') {
callBack(response);
} else {
console.log('error');
}
}
});
}
I just need "id" and "status" which will be "0" or "1" in my controller. I am not sure what I am doing wrong ?
Level 5
@gemini_man93 Or if you'd like another approach. Try this.
$(document).on('click', '#status_update', function (e) {
let status = $(this).prop('checked') === true ? 1 : 0;
let firmware_id = $(this).data('id')
let url = "{{ route('changeStatus', '') }}/" + firmware_id;
let data = {status}
Send_Ajax_Req_To_Server(
'GET',
data,
url,
'',
updatedStatus
);
});
And in your Send_Ajax_Req_To_Server method. Update processData value to true. And you're good to go.
1 like
Please or to participate in this conversation.