user6408005 user6408005 - 6 months ago 13
Javascript Question

data in alert box using javascript



I try to populate data in alert box on button click but when I click on button then alert box not populate

I try this

<head runat="server">
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

</head>

<body>
<form id="form1" runat="server">
<div>
<button id="submitchart" runat="server">Show Chart</button>
</div>
</form>
</body>
<script type="text/javascript">
$('#submitchart').click(function() {
//alert("i");
$.ajax({
type: 'POST',
//url: 'WebForm1.aspx / Jqufunc',
//data: JSON.stringify({ yearP: $('#yearValue').val() }),
//data:{},
contentType: 'application/json;charset=utf-8',
dataType: 'json',
success: function() {
//alert(JSON.stringify(response.d));
alert("i");
}

});
});
//});
</script>


when I write alert("i") after this line
$('#submitchart').click(function () {
then alert box populate but when i write alert ("i") after the
success: function() {
then alert box not populate

any solution?

Answer

  $(function () {
            $("#submitchart").on("click", function () {
                debugger;
                alert("i");
                $.ajax({
                    type: 'POST',
                    //url: 'WebForm1.aspx / Jqufunc',
                    //data: JSON.stringify({ yearP: $('#yearValue').val() }),
                    //data:{},
                    contentType: 'application/json;charset=utf-8',
                    dataType: 'json',
                    success: function () {
                        //alert(JSON.stringify(response.d));
                        debugger;
                        alert("i");
                    },
                    error: function () {
                        debugger;
                        alert("i");
                    }

                });

ajax will be run error,don't run success

Comments