Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. $.ajax({
  2. method: 'POST',
  3. url: '/parts',
  4. data: $( this ).serialize(),
  5. dataType: 'json',
  6. success: function (result) {
  7. console.log(result);
  8.  
  9. details = result.products;
  10. cars = result.cars;
  11. models = result.models;
  12. engines = result.engines;
  13. years = result.years;
  14. aggrs = result.aggrs;
  15.  
  16. $('#productsTable').html( result.products_html );
  17. $('#paginate').html( result.paginate );
  18. $('#productsIds').val( result.products_ids );
  19.  
  20. if ( typeof result.cars !== 'undefined' && Object.keys( result.cars ).length && carVal ) {
  21. $('#formSelectCar').html( '<option value="0">Марка</option>' );
  22. $.each(result.cars, function( index, value ) {
  23. // console.log(index, value);
  24. option = '<option value="' + value.id + '">' + value.name + '</option>';
  25. $('#formSelectCar').append( option );
  26. });
  27. }
  28.  
  29. if ( typeof result.models !== 'undefined' && Object.keys( result.models ).length && modelVal ) {
  30. console.log('models', result.models);
  31. if($('#formSelectCar').val() != 0) {
  32. carId = $('#formSelectCar').val();
  33. console.log('each models', carId);
  34.  
  35. $('#formSelectModel').html( '<option value="0">Модель</option>' );
  36. $.each(result.models[carId], function( index, value ) {
  37. console.log(index, value);
  38. option = '<option value="' + value.id + '">' + value.name + '</option>';
  39. $('#formSelectModel').append( option );
  40. });
  41. }
  42. }
  43. if (result.years) {
  44. $('#formSelectYear').html( '<option value="0">Год</option>' );
  45. $.each(result.years, function (index, value) {
  46. option = '<option value="' + value.id + '">' + value.name + '</option>';
  47. $('#formSelectYear').append( option );
  48. });
  49. }
  50. if (result.aggrs) {
  51. $('#formSelectAggr').html( '<option value="0">Код</option>' );
  52. $.each(result.aggrs, function (index, value) {
  53. option = '<option value="' + value.id + '">' + value.name + '</option>';
  54. $('#formSelectAggr').append( option );
  55. });
  56. }
  57. if (result.engines) {
  58. $('#formSelectEngine').html( '<option value="0">Код</option>' );
  59. $.each(result.engines, function (index, value) {
  60. option = '<option value="' + value.id + '">' + value.name + '</option>';
  61. $('#formSelectEngine').append( option );
  62. });
  63. }
  64. }
  65. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement