I basically need to use insertBefore and appendChild with a Server Side rendered HTML page jQuery AJAX result. I get the error: "Failed to execute 'inserBefore' on 'Node': parameter 1 is not of type 'Node'."
var parent_elem = $('#parent_elem');
$.ajax({
type:'POST',
url:'example.com/my_ajax_call',
data: {"my_data":my_data},
success:function(data){
parent_elem.prepend(data); //THIS IS THE JQUERY SOLUTION BUT I NEED PURE JS WHILE USING JQUERY AJAX REQUEST
},
fail:function(data){
console.log(data);
console.log('failed to load page');
}
});
what I am trying to do is this:
var parent_elem = document.getElementById('parent_elem');
$.ajax({
type:'POST',
url:'example.com/my_ajax_call',
data: {"my_data":my_data},
success:function(data){
parent_elem.inserBefore(data, parent_elem.firstChild); //THIS IS WHAT I NEED BUT IT THROWS ERROR "Failed to execute 'inserBefore' on 'Node': parameter 1 is not of type 'Node'."
},
fail:function(data){
console.log(data);
console.log('failed to load page');
}
});
Via Active questions tagged javascript - Stack Overflow https://ift.tt/FoRM2K3
Comments
Post a Comment