Created
January 14, 2020 04:02
-
-
Save mazfreelance/cc343e85d8c2433112637338e258723a to your computer and use it in GitHub Desktop.
append data to selection form using ajax
This file contains 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
$.ajax({ | |
url: '../example.php', | |
type: 'post', | |
data: {}, | |
success: function( data, textStatus, jQxhr ){ | |
// console.log(data); | |
var itemID = <?php echo json_encode($item_id); ?>; | |
// console.log(itemID); | |
$.each(data['data'], function(key, value) { | |
$('select#select_item').append($("<option></option>").attr("value",key).text(value)).trigger('change'); | |
if(itemID){ | |
$.each(itemID, function(id, item) { | |
if(key == item){ | |
$('select#select_item option[value="'+item+'"]').prop("selected", true); | |
} | |
}); | |
} | |
}); | |
}, | |
error: function( jqXhr, textStatus, errorThrown ){ | |
console.log( errorThrown ); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment