Send form serialize to asp.net webmethod
The project continues . .
I have a form that I'm serializing with the jquery form plugin. Works great.
I am then using the jquery ajax feature to post to an asp.net web method so that eac开发者_StackOverflow社区h form element can be inserted into a database.
My issue is this, how do I loop through each of the request.form params that is sent via ajax in the asp.net web method. If I use a standard Request.Form("") I receive an error. Here is my code.
var queryString = $('input').fieldSerialize();
$.ajax({
type: "POST",
url: "Detail.aspx/doPostTest",
data: "{ 'txtQuery': '" + queryString + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var products = eval(data.d);
console.log(products);
}
});
Code behind
<System.Web.Services.WebMethod()> _
Public Shared Function doPostTest(ByVal txtQuery As String) As String
'Grab Request Form variables
Request.Form("txtMember")
End Function
The error I receive on the server side is the following:
Cannot refer to an instance member of a class from within a shared method or shared member . . etc.
Thanks in advance.
You will need to call HttpContext.Current.Request
to access your current HttpRequest
from static methods.
The Page
class your page inherits from contains an instance property Request
; therefore it's not possible to access this prop from your static methods.
精彩评论