Skip to content

How to create POST request to specified action? #1021

Closed

Description

@itg-assistant

Truong Nguyen asked 2017-08-16 11:31:53 UTC

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.

Activity

  1. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Luca answered 2017-08-16 15:12:05 UTC

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

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

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

  2. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Truong Nguyen answered 2017-08-17 02:50:02 UTC

    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?

  3. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Luca answered 2017-08-17 16:29:35 UTC

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    GeneralQuestions, how-tos and everything else.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions