How to create POST request to specified action?


As the title, I want to create an ajax Post method to the server.
How can I create an action link for Ajax can post the data to that action.

Something like that:

url: action_url,
method: ‘POST’,
data: {}

How can I create the “action_url” from the server?
Thank you.

  • You must to post comments

See attached sample. Uses two different ajax requests, the first uses jquery, the second uses the built-in xhr object so you don’t need to download jquery:

  • You must to post comments

What do you need to do?

For a simple ajax request you can use any ajax library, like jQuery, or you can use the XMLHttpRequest class directly.

If you need to invoke an action on the server, with Wisej you can simply add a public static [WebMethod] method to Program.cs and then call it from javascript using App.{methodName}(args); You can even receive the return value like this:

App.{methodName(args, function(retVal) { … });

If you add a public non-static [WebMethod] to a top level control (Form or Page or Desktop) then you can call it from JavaScript directly on the object.

Another way is to implement the IWisejHandler interface on a class. Or you can use a Wisej.Web.Widget and handle the WebRequest event. In which case the URL is this.GetPostbackURL(). See this:

See attached sample for the [WebMethod] approach. Look at the JavaScriptEvents attached to the buttons.



  • Truong Nguyen
    I have used the Wiget with WebRequest Event: private void _ganttWidget_WebRequest(object sender, WebRequestEventArgs e) { e.Response.ContentType = “application/json”; e.Response.Write(new { test = “text” }); } And in the InitScript, I used the ajax to request: $.ajax({ url: this.getPostbackUrl(), method: ‘POST’, data: null, success:function(response){ console.log(response); } }); However, the ajax request is not working. I also include Jquery Ajax library in the Widget packages. Did I misunderstand something?
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.