简体   繁体   中英

Jquery AJAX button call in Umbraco BackOffice

Hi I just created a simple new option for umbraco backoffice, it is a simple html page which displays a button to click. Simple form

This button should send an ajax call to an UmbracoApi, but the request never reaches the webapi. Below the Api Code: API Code

The Ajax call is a simple Jquery Ajax call in the event click of the html button.

I'll appreciate any help you can provide me, in order to complete this ajax call.

I think yor problem is the way you are calling it:

  1. not sure if url casing not same as Controller and action will cause routing failure or not, but might as well make then the same
  2. you action is binding a primitive type, from my understanding of webapi - primitive type will check at querystring otherwise specifically tell it to look at body more info about this, checkout https://docs.microsoft.com/en-us/aspnet/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api

so base on above two statement, try change your call to:

$("#btnGetData").click(function() {
    $.ajax("http://localhost:44302/Umbraco/Api/StripeBackOfficApi/GenerateLockBoxile?date=" + $('#txtDate').val(), {
            type: "GET"
        }, cache: false, success: function(data, status, headers, config) {
            if (data) {
                alert("Done!");
            }
        }, error: function(jqXHR, timeout, message) {
            console.log("Error: " + message);
        }
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM