对.NET代码隐藏的jQuery AJAX调用将不会返回

时间:2022-10-08 08:29:10

adAsText(file);

    $.ajax({
        url: "WebForm1.aspx/OnSubmit",
        rn "abcd";
}

it is a success and all the contents of the file prints as an alert, but I can't get it to return. It there something wrong with the content/data type?

它是成功的,文件的所有内容都打印为警报,但我不能让它返回。内容/数据类型有问题吗?

2 个解决方案

#1


0  

Your Code is not clear. I think you should clear it as much as possible. The Error I see is that you are not calling the server side function anywhere. Then how you hope to be having returned data. First Call the function by passing a string value to it.

您的准则不明确。我想你应该尽可能地清除它。我看到的错误是你没有在任何地方调用服务器端功能。然后你希望如何返回数据。首先通过向其传递字符串值来调用该函数。

I think this is your problem, if not, please clarify more.

我认为这是你的问题,如果没有,请澄清一下。

#2


0  

Try changing dataType to json. Even though it should infer, it's better to be explicit.

尝试将dataType更改为json。即使它应该推断,最好是明确的。

$.ajax({
    url: "WebForm1.aspx/OnSubmit",
    type: "POST",
    data: file,
    dataType: "json",
    contentType: "plain/text; charset=utf-8",
    processData: false,
    error: function (msg) {
        console.log(msg.d);
        alert("error");
    },
    success: function (msg) {
        console.log(msg.d);
        alert(file);
    }
});

#1


0  

Your Code is not clear. I think you should clear it as much as possible. The Error I see is that you are not calling the server side function anywhere. Then how you hope to be having returned data. First Call the function by passing a string value to it.

您的准则不明确。我想你应该尽可能地清除它。我看到的错误是你没有在任何地方调用服务器端功能。然后你希望如何返回数据。首先通过向其传递字符串值来调用该函数。

I think this is your problem, if not, please clarify more.

我认为这是你的问题,如果没有,请澄清一下。

#2


0  

Try changing dataType to json. Even though it should infer, it's better to be explicit.

尝试将dataType更改为json。即使它应该推断,最好是明确的。

$.ajax({
    url: "WebForm1.aspx/OnSubmit",
    type: "POST",
    data: file,
    dataType: "json",
    contentType: "plain/text; charset=utf-8",
    processData: false,
    error: function (msg) {
        console.log(msg.d);
        alert("error");
    },
    success: function (msg) {
        console.log(msg.d);
        alert(file);
    }
});