Generic Handler ashx file : Post send JSON data in Asp.net c#, jQuery

2
Our Reader Score
[Total: 0 Average: 0]
Jquery ajax, post data t generic handler :  Here in this tutorial will explain how easily we can post or send  JSON string ( data ) using jQuery to the generic handler ( ashx file) in Asp.net, C#. In another word How we can send parameters, data to Generic handler (ashx) file using jquery ajax (client side). You can also check my previous article on Asp.net, C#, jQuery, JSON  and  jQuery Ajax JSON Example in Asp.net with sql database

Firstly, you will need to include latest jQuery .js file from the Google-hosted site. You can also host the jQuery file on your server, it’s all your choice. Now add a button tag, which trigger click event and send / post data to the generic handler.


# HTML Markup:


# Client-Side: Jquery- calling ajax on button click to send JSON data.

On button click, we calling ajax method, and send user data. i.e. First name, Last name, Qualification, and Age. You may notice in below client-side code under ajax method we have used data: jsonData, this is important here bcoz we are going to send / post JSON object on

You may notice in below client-side code under ajax method we have used data: jsonData, this is important here bcoz we are going to send / post JSON object on server. This is how our client side looks like.


# Add Generic Handler ( ashx file) in your Asp.net Application.

First, import those two namespaces as shown in below code.

Now we add a userInfo class into our generic handler ( ashx file ), which matches with our client side JSON object.

This is our ProcessRequest method, where we retrieve parameter, data from client side ajax call.

Yeah, we are done now. Hit F5 and enjoy 🙂

Full Code of Generic Handler ( ashx file ).

 

You must check these article:

Hope you enjoyed this tutorial. If you have any recommendations, please let us know what you think in the comment section below! See you again next time!


Get your Printable Copy

2 COMMENTS

  1. Very nice! Thank you. However, your jQuery gave me errors in Chrome, Edge. It only works in ie11. Any suggestion?
    Also, the jQuery should be
    success: function (jsondata) {
    console.log(jsondata);
    alert(“Success :” + jsondata);
    data gave me the content of GenericHandler.ashx

LEAVE A REPLY