How to create POST request to specified action?

0
0

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:

$.ajax({
url: action_url,
method: ‘POST’,
data: {}
});

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

  • You must to post comments
2
0

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: http://www.qooxdoo.org/5.1/api/#qx.io.request.Xhr

  • You must to post comments
0
0

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) { … });

https://wisej.com/docs/html/JavaScriptObjectModel.htm

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: https://wisej.com/support/question/serving-static-content

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

 

 

Attachment
  • 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.