Jquery ajax将formdata发送到ASP.NET网页(aspx.cs) [英] Jquery ajax send formdata to ASP.NET webpage (aspx.cs)

查看:406
本文介绍了Jquery ajax将formdata发送到ASP.NET网页(aspx.cs)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的ajax请求

  function  sendData(){
var formdata = new FormData();
var fileUpload = $( #txtUploadFile )。get( 0 );
var files = fileUpload.files;
for var i = 0 ; i< files.length; i ++){
formdata.append(files [i] .name,files [i]);
}
formdata.append( PaymentDate new Date ());
$ .ajax({
url:' CCA_Form.aspx / SendData'
类型:' POST'
data:formdata,
contentType: false
processData: false
成功: function (){
alert( 数据已成功添加 );
},
错误: function (){
alert( 插入数据时出错);
}
});
}

我的服务器方法是这样的

 [WebMethod] 
public static string SendData()
{ // 此处的断点
// code
return 返回数据;
}

ajax方法始终显示成功消息,webmethod不在服务器端点击。你能帮我解决一下我错过的代码吗?提前致谢。



我的尝试:



如何使用jquery ajax将formdata发送到aspx.cs页面?

解决方案

#txtUploadFile)。get( 0 );
var files = fileUpload.files;
for var i = 0 ; i< files.length; i ++){
formdata.append(files [i] .name,files [i]);
}
formdata.append( PaymentDate new Date ());


.ajax({
url: ' CCA_Form.aspx / SendData'
类型:' POST'
data:formdata,
contentType: false
processData: false
成功: function (){
alert( 数据已成功添加);
},
错误: function (){
alert( 插入数据时出错);
}
});
}

我的服务器方法是这样的

 [WebMethod] 
public static string SendData()
{ // 此处的断点
// code
return 返回数据;
}

ajax方法始终显示成功消息,webmethod不在服务器端点击。你能帮我解决一下我错过的代码吗?提前致谢。



我的尝试:



如何使用jquery ajax将formdata发送到aspx.cs页面?


明显的webMethod将不会执行



你已经传递了数据AJAX POST方法



数据:formdata,





但是你的web方法中没有参数。



 [WebMethod] 
公共静态字符串SendData()
{//断点这里
//代码
返回返回数据;
}





我希望对您来说已经足够了,如果您对此有任何疑问或疑虑,请告诉我。


Below is the my ajax request

function sendData() {
    var formdata = new FormData();
    var fileUpload = $("#txtUploadFile").get(0);
    var files = fileUpload.files;   
    for (var i = 0; i < files.length; i++) {
        formdata.append(files[i].name, files[i]);
        }
    formdata.append("PaymentDate", new Date());
    $.ajax({
        url: 'CCA_Form.aspx/SendData',
        type: 'POST',
        data: formdata,
        contentType: false,
        processData: false,
        success: function () {
            alert("Data Added Successfully");
        },
        error: function () {
            alert("Error while inserting data");
        }
    });
}

and my server method is like this

[WebMethod]
    public static string SendData()
    {//break point here
        // code
        return "return data";
    }

the ajax method always showing success message and webmethod not hitting in server side. Could you help me what i missed in my code? Thanks in advance.

What I have tried:

How to send formdata to aspx.cs page using jquery ajax?

解决方案

("#txtUploadFile").get(0); var files = fileUpload.files; for (var i = 0; i < files.length; i++) { formdata.append(files[i].name, files[i]); } formdata.append("PaymentDate", new Date());


.ajax({ url: 'CCA_Form.aspx/SendData', type: 'POST', data: formdata, contentType: false, processData: false, success: function () { alert("Data Added Successfully"); }, error: function () { alert("Error while inserting data"); } }); }

and my server method is like this

[WebMethod]
    public static string SendData()
    {//break point here
        // code
        return "return data";
    }

the ajax method always showing success message and webmethod not hitting in server side. Could you help me what i missed in my code? Thanks in advance.

What I have tried:

How to send formdata to aspx.cs page using jquery ajax?


Obvious webMethod will not going to execute

You have passed data in AJAX POST method

data: formdata,



But there is no parameters in your webmethod.

[WebMethod]
    public static string SendData()
    {//break point here
        // code
        return "return data";
    }



I hope it is enough for you, Let me know if you have any query or concern for same.


这篇关于Jquery ajax将formdata发送到ASP.NET网页(aspx.cs)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆