I would say get everything working first without using Ajax then go back to your Ajax try that.
Jul 7, 2016
7
Level 1
Need some help with jQuery
I have a search page where users can find companies and view their ratings. When user click on City select button, ajax is called which represent table with two columns - name of the company and company's rating . It works with name of the company, but rating is the problem.
I have two tables in mysql: Companies -id -nameOfTheCompany
Services -id -serviceType -idCompany(FK) -rating
Routes:
Route::get('ajax-subcat', 'CompanyController@test');
CompanyController:
public function test()
{
$cat_id = Input::get('cat_id'); //Here i get city's name from select input
$subcategories = Companies::where('city', '=', $cat_id)->get();
return response()->json($subcategories);
}
And script:
$('#categories').on('click', function(e){
var cat_id = e.target.value;
//ajax
$.get('/ajax-subcat?cat_id=' + cat_id, function(data){
$('#podaci').empty();
$.each (data, function(index, subcatObj){
$('#podaci').append(
'<tr><td>'+subcatObj.nameOfTheCompany+'</td> <td>'
+'<div class="rate2" data-rate-value ="{{ HERE IS THE PROBLEM }}"</td></tr>');
});
});
});
How can I manage to get data-rate-value like I've mentioned in code?
Please or to participate in this conversation.