JavaScript, jQuery, jQuery AJAX

How to Call ASMX WebService using HTTP GET with jQuery AJAX

By Default , WebMethod of ASMX is not allowed to be called using HTTP GET . So we will see a short demo here . Our HTML Markup of the aspx page is :

<asp:DropDownList ID="DropDownList2" runat="server" Width="150">
           <asp:ListItem Text="Select" Value="-1" />
        </asp:DropDownList>

We will fill this DropDown By calling ASMX Service’s WebMethod using HTTP GET with jQuery Ajax . My Client Code is like below :::

var DropDownList2 = $("#<%= DropDownList2.ClientID %>");
         

         $.ajax({
                type: "GET",
                url:"<%=ResolveUrl("~/MyWebService.asmx") %>/GetAllProjectName",
                data:"{}",
                contentType:"application/json; charset=utf-8",
                dataType:"json",
                success: function(response){
                        var projects = response.d;
                        $.each(projects,function(index,project){
                            DropDownList2.append('<option value="'+ project.ProjectId +'" >' + project.ProjectName + '</option>');                        
                        });
                 }
         });

My Server side code of the WebService is :::

[WebMethod]
         [ScriptMethod(UseHttpGet = true)]
         public List<ProjectOfEmployee> GetAllProjectName()
         {
             return GetProjectName();   
         }

Remember to add the below part of course

[ScriptMethod(UseHttpGet = true)]

Otherwise , It will give 500 Internal Server Error .

So now you are done 🙂 Cheers

Standard

One thought on “How to Call ASMX WebService using HTTP GET with jQuery AJAX

Leave a Reply

Your email address will not be published. Required fields are marked *