┼Żygimantas Pranka ┼Żygimantas Pranka - 7 months ago 19
Javascript Question

Where to put Error Alert in my JS

Hi there! So I wanted to ask where I need to place Error Alert code in this JS and if it is of any use in such JS.

<script>
$(document).ready(function () {
$.get("ImagePreview?b_id=<%=id%>", function (responseJson) {
var $select = $("<div>").addClass("galleria").appendTo($("#imgas"));
$.each(responseJson, function (index, item) {
$("<img />").attr("src", item).appendTo($select);
});
});
});
</script>

Answer
  • Put an alert every odd line like alert("A"), alert("B") etc
  • Refresh the page
  • Remove every alert from your code and keep the one you like best

P.S: if you want to test the actual responseJson than alert is a bad idea.
Use console.dir(responseJson); inside your AJAX function.