I have a problem calling ajax from appended content.
Let's show you my example (An example calling ajax request from appended content, and other call ajax request from none appended content):
https://jsfiddle.net/r7f3zo92/
$(document).ready(function() {
new AjaxUpload("#change", {
action: 'verifImg',
name: 'uploadfile',
onSubmit: function(file, ext) {
if (!(ext && /^(png|jpeg|jpg|bmp|gif)$/.test(ext))) {
return false;
}
},
onComplete: function(file, response) {
$("#imagechange").html(response);
}
});
$(document).on('click', '#test', function(ev) {
$('body').find('#show').remove();
var modal =
'<div class="modal fade" id="show" tabindex="-1" role="dialog" aria-labelledby="show">' +
'<div class="modal-dialog" role="document">' +
'<div class="modal-content">' +
'<div class="modal-header">' +
'<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>' +
'<h4 class="modal-title" id="myModalLabel">Test</strong></h4>' +
'</div>' +
'<div class="modal-body">' +
'<div class="row">' +
'<div class="form-group">' +
'<a href="#" class="btn btn-sm btn-default" id="change">Change Image</a>' +
'<br/>' +
'<div id="imagechange"></div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>';
$('body').append(modal);
$('#show').modal({
show: true
});
return false;
});
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="http://www.phpclasses.org/browse/download/1/file/51812/name/ajaxupload.3.5.js"></script>
<strong>Example with appended content:</strong>
<br/>
<a href="#" id="test">An example to test</a>
<br/>
<br/>
<strong>Direct example:</strong>
<br/>
<div class="form-group">
<a href="#" class="btn btn-sm btn-default" id="change">Change Image</a>
<br/>
<div id="imagechange"></div>
</div>
In JSFIDDLE it's work fine, but locally no ! strange !
Can you find the problem related to this example ? Thank's