I am going to send an AJAX request inside a Laravel Blade. This is my code:
function submitForm(userId) {
var ajaxUrl = '{!! route("user-role-update", '+userId+') !!}'
$.ajax({
type: 'PUT',
url: ajaxUrl,
data: {
_token: "{!! csrf_token() !!}",
'newRoles': userRoleTableData
},
In the controller, I returned the userId to check if the userId is passed to the URL or not, but the result was not returning the userId:
{
"msg": "Something wrong while deleting the old roles--",
"id":"+userId+",
"isUserRoleSaved":false
}
Instead of returning the userId, it returns the variable "userId" with the "+" from JS script. How can I solve this?
https://example.com/{userId}. What PHP sees when it's rendering is "+userId+", when in fact that's only defined in the client. Either change your implementation on the server side to not require a userID URL at render or send 2 AJAX requests.