繁体   English   中英

Webmethod在ajax调用中未受到攻击

[英]Webmethod not getting hit in ajax call

我从我正在调用一个具有对C#webmethod的ajax post调用的函数的地方有angular js指令。

app.directive("fileread", [function () {
return {
link: function ($scope, $elm, $attrs) {
  $elm.on('change', function (changeEvent) {
   var data = "some json data";   
        test(data);           
      });
    };
  };
}]);

从指令调用的函数

function test(json_object){
     $.ajax({
        type: "POST",
        url: "/sites/Demo/_layouts/15/demo/demowebmethod.aspx/mywebmethod",
        data: json_object,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: OnSuccess,
        failure: function(response) {
           alert(response.d);
        }
     });    
}

function OnSuccess(response) {
    alert(response.d);
}

它既不调用Web方法,也不调用成功或失败,而是控件进入test功能。 任何提示,我要去哪里错了。

$ .ajax中没有failure回调:

failure: function(response) {
     alert(response.d);
}

更改为error:或使用诺言

error: function(response) {
     alert(response.d);
}

http://api.jquery.com/jquery.ajax/

可能是由于网络方法导致的错误,但是您没有看到它。 通过将url更改为明显不存在的内容进行确认,例如“ ... / mywebmethodxxxxxxx”

将此添加到您的ajax调用中。 它应该给您更好的信息以采取行动。

 error: function (request, status, error) {
                alert('Error: ' + error);
            }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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