Skip to content

Instantly share code, notes, and snippets.

@rslahmed
Last active September 5, 2020 19:21
Show Gist options
  • Save rslahmed/653b97dccae88834c34443dfb5482336 to your computer and use it in GitHub Desktop.
Save rslahmed/653b97dccae88834c34443dfb5482336 to your computer and use it in GitHub Desktop.
Ajax call with jQuery
$('#add').click(function () {
var id = $(this).attr("target-id");
var data = {id : id};
// if type post
// { _token: "{{ csrf_token() }}", id: id}
$.ajax({
type:"GET",
cache:false,
url:"welcome.php",
// if send with formData then
// processData: false, contentType: false,
data:data,
success: function (response) {
console.log(response)
}
});
});
//on change get sub category
$('#category_id').on('change', function(){
let id = $(this).val();
$.get( "{{url('admin/get_subcategory_bycategory')}}",{id: id}, function( data ) {
$('#subcategory_id option:not(".default")').remove();
$.each(JSON.parse(data), function(key, value){
let html = `<option value="${value.id}">${value.name}</option>`;
$('#subcategory_id').append(html);
})
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment