Search code examples
jqueryasp.netprototypejs

change Prototype to JQuery in asp.net


At the header I have the following

<script language="javascript" type="text/javascript">
function setConBal() {
    conBal = 1;
}
function readBalance() {
    new Ajax.Updater('tableBalance', '_Bet/PanelBalance1.aspx', { method: 'post', onComplete: setConBal });
}
function preReadBalance() {
    new Ajax.Updater('tableBalance', '_Bet/PanelBalance1.aspx', { method: 'post' });
}
</script>

Inside Body I have a div with ID = tableBalance and the end of body tag I have this to call the JS functions

<script type="text/javascript">readBalance(); preReadBalance();</script>

The js functions are suppose to call PanelBalance1.aspx to generate a HTML table and put it into the div, it works fine when using prototype, but now I need to do the exact same thing using JQuery. I tried to change the function to JQuery syntax but it din't work.

function readBalance() {
    $.ajax({
        type: 'post',
        url: "_Bet/PanelBalance1.aspx",
        complete: function(r) {
        $('#tableBalance').html(r);
            setConBal();
        }
    });
}

function preReadBalance() {
    $.ajax({
        type: 'post',
        url: "_Bet/PanelBalance1.aspx"
    });

}

No error when I changed to this syntax but at the same time no Output either... Am I doing this in a wrong way??


Solution

  • Try this

    function readBalance() {
        $.ajax({
            type: 'post',
            url: "_Bet/PanelBalance1.aspx",
            success: function(data) {
            $('#tableBalance').html(data);
                setConBal();
            }
        });
    }