Reputation: 357
There is an Ajax call that works on other pages, but not on the very page I want to use it. Here's the script:
<script type="text/javascript">
var city = "مشهد";
$.ajax({
method: 'GET',
url: '/changecredsgrabdata',
data: {id : city},
success: function(response){
alert(JSON.stringify(response));
}
});
</script>
Here is the route:
Route::get('/changecredsgrabdata', 'LoginController@placeholders');
And here is the controller method:
public function placeholders(Request $req) {
$qer = $req->id;
$user_id = SESSION::get('user_id'); //GETTING USER ID
foreach($user_id as $key=>$item){
$user_id[$key]= (array)$item;
}
$user_id = $user_id[0]["user_id"]; /////////////////
$user_data = DB::select
('SELECT user_mail ,user_firstname, user_family, user_mobile FROM app_users WHERE user_id= ?' , [$user_id]);
return response()->json($user_data);
}
The ajax works in other pages, also $user_data isn't empty and is exactly what I want. I also passed an id of city and used it on the first line of my method, but I don't need any data to be sent at all and I only sent it because I didn't know how not to send any data. so ignore that bit.
Upvotes: 2
Views: 45
Reputation: 357
Okay, I found the solution and I can't believe to have made such stupid mistake. I didn't add jQuery. So I added a simple line in the head of html and the problem is solved. Here's the line of code:
<script src="http://code.jquery.com/jquery.min.js"></script>
Upvotes: 1