简体   繁体   中英

ASP.net requesting posted form data always null

The following Javascipt:

$.ajax({
    type: "POST",
    data: "langID=" + viewingLangID + "&currency=" + newVal + "&basePrices=" + pricePostData,
    dataType: "json",
    url: "/handlers/payments/getconversions.ashx",
    success: function(data) {

Produces the following HTTP request:

General
Request URL:https://127.0.0.1:3333/handlers/payments/getconversions.ashx
Request Method:POST
Status Code:200 OK
Remote Address:127.0.0.1:3333

Response Headers
Cache-Control:private
Content-Length:78
Content-Type:application/json; charset=utf-8
Date:Mon, 01 Feb 2016 17:35:41 GMT
Server:Microsoft-IIS/8.5
X-AspNet-Version:4.0.30319
X-MiniProfiler-Ids:["9d45ff72-2efa-4d31-a5c7-c109573699c6"]
X-Powered-By:ASP.NET

Request Headers
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Connection:keep-alive
Content-Category:application/x-www-form-urlencoded; charset=UTF-8
Content-Length:62
Content-Type:text/plain;charset=UTF-8
Cookie:C3_Login=ID=e99af6ee-b0fc-4d92-89f6-262d37d7a2b0&Key=BAFKzQhxZsknMyE1bvbjsFouDvaZUSxVzP0oGmN8kONCJRUR1z; _gat=1; _ga=GA1.1.1302222369.1453808296; C3_Currency=GBP
Host:127.0.0.1:3333
Origin:https://127.0.0.1:3333
Referer:https://127.0.0.1:3333/?p=ContentIndividuals
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36
X-Requested-With:XMLHttpRequest

Request Payload
langID=2&currency=GBP&basePrices=299,799,2499,9999,10999,13999

However, on getconversions.ashx if I do:

context.Request.Form["currency"]

The value is always null . Any idea why this might be? I've tried Request["currency"] and Request.Params["currency"] but it always returns null .

If I log context.Request.ServerVariables["ALL_RAW"]

Connection: keep-alive
Content-Length: 62
Content-Type: text/plain;charset=UTF-8
Accept: application/json, text/javascript, */*; q=0.01
Accept-Encoding: gzip, deflate
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Cookie: C3_Login=ID=e99af6ee-b0fc-4d92-89f6-262d37d7a2b0&Key=BAFKzQhxZsknMyE1bvbjsFouDvaZUSxVzP0oGmN8kONCJRUR1z; _gat=1; _ga=GA1.1.1302222369.1453808296; C3_Currency=GBP
Host: 127.0.0.1:3333
Referer: https://127.0.0.1:3333/?p=ContentIndividuals
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36
Content-Category: application/x-www-form-urlencoded; charset=UTF-8
Origin: https://127.0.0.1:3333
X-Requested-With: XMLHttpRequest

Try converting your data to an object. Currently the data is not in a json format.

var jsonData = {'langID':viewingLangID, 'currency':newVal, 'basePrices':pricePostData}

$.ajax({
    type: "POST",
    data: jsonData,
    dataType: "json",
    url: "/handlers/payments/getconversions.ashx",
    success: function(data) {

Also note that the values for pricePostData should be an array for json [123,234,456,567] etc..

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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