Last active
September 5, 2020 19:21
-
-
Save rslahmed/653b97dccae88834c34443dfb5482336 to your computer and use it in GitHub Desktop.
Ajax call with jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#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