Using jQuery's getJSON method with an ASP.NET Web Form

前端 未结 3 1451
清酒与你
清酒与你 2020-12-05 08:32

How do I go about calling a method on an ASP.NET Web Form page using the getJSON method on jQuery?

The goal is this:

  1. User clicks on a list item
3条回答
  •  -上瘾入骨i
    2020-12-05 09:33

    I tweaked your code a bit. I added the server side output of the ClientID to the updateRegions method to pass it in. And I changed your getJSON method to pass in the url with a query string parameter (instead of separate data) and the call back function.

    jQuery(document).ready(function() {
       jQuery("#<%= AreaListBox.ClientID %>").click(function() {
           updateRegions(<%= AreaListBox.ClientID %>);
       });
    });
    
    function updateRegions(areaId) {
        jQuery("h2").html("AreaId:" + areaId);
    
        jQuery.getJSON("/Locations.aspx/GetRegions?" + areaId, 
            function (data, textStatus) {
                debugger;
            });
    }
    

    Let me know if that works!

提交回复
热议问题