Surendra Mourya Surendra Mourya - 5 months ago 38
C# Question

Webmethod not getting hit in ajax call

I have angular js directive from where i am calling one function which has ajax post call to c# webmethod.

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

The functions which get called from directive

function test(json_object){
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) {

function OnSuccess(response) {

It is not hitting the web method neither the success or failure getting called but control goes inside
function. Any clues where i am going wrong.


Add this to your ajax call. It should give you a better message to act on.

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