Why is my REST method not being called by this jQuery?

前端 未结 5 1864
星月不相逢
星月不相逢 2021-01-25 21:32

I have a similar question about jQuery button click handler code not being fired at all here.

In this case, it is being fired (when the jQuery is added to a sta

5条回答
  •  耶瑟儿~
    2021-01-25 22:16

    Regarding your point:

    If I manually enter that URL in the browser, so that the URL bar reads "http://localhost:52194/api/ABUELOS/2016-08-21/2016-08-27" it works - the method is reached and it "does its thing."

    Modifying your Ajax call like shown below should solve your problem and will send a GET request to the mapped url (Showing with button click event handler):

     $("#btnGetData").click(function () {
    
       var unitval = 'ABUELOS';
       var begdateval = '2016-08-21';
       var enddateval = '2016-08-27';
    
       $.getJSON("api/" + unitval + "/" + begdateval + "/" + enddateval,
          function (Data) {
            // do what ever you want with the success response
          })
          .fail(
            function (jqXHR, textStatus, err) {
              // do what ever you want with the failed response
          });
     });
    

提交回复
热议问题