Quantcast
Channel: c# equivalent of JavaScript
Viewing all articles
Browse latest Browse all 4

c# equivalent of JavaScript

$
0
0

There several ways to do the equivalent of the AJAX call. This is essentially an HTTP POST to a URL, including a payload. In C# such a POST can be accomplished with theWebClient class or with an HttpClient class. There are examples in the documentation:

https://docs.microsoft.com/en-us/dotnet/api/system.net.webclient

https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient

You will need to assemble the payload for the complex data. Typically you would define in your code a class to contain the complex data, and then serialize it as JSON and insert the resulting JSON in the body of the POST request. There are many JSON serializers but one of the most common ones is Newtonsoft.Json, which you can add as a NuGet package to your C# project.

If you use the HttpClient, you can call the PostAsync method to make your Ajax call. In this case, PostAsync will return aTask object. The Task itself provides most of the capabilities that you would be using from thedeferred object, so you can operate directly with the Task without needing to find any other equivalent for Deferred.

https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task


Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>