Javascript function undefined error when using ajax inside the function body

I am calling a function on onchange event of checkbox and it is working well but when I insert the ajax code in my function body,uncaught error function is undefined arises.
Please take a look at my code so far:

input type="checkbox" onclick="OnChangeCheckbox (1)" id="myCheckbox1" value="22" />
    <label for="myCheckbox">Sample check box</label> 

and javascript function is:

function OnChangeCheckbox (checkbox) {
    var k = checkbox;
    if ($("#myCheckbox"+k.value).is(":checked")) {  
        $.ajax({
            async: false,
            url: 'getCDP.php', 
            data: { "size": vsize1},
            dataType: 'json',  
            success: function(data) {
                alert{"ssdsd");
            }
        });
    }
    else {
        alert ("The check box is not checked.");
    }
}


Source: ajax

Leave a Reply