Why can't I retrieve the value on the server after I submit data to ashx using Ajax and format the parameter with JSON. stringify? [Reprint to: http://q.cnblogs.com/q/34266/]

Source: Internet
Author: User

Front-end code:

$ (Function (){
VaR model = function (key ){
This. Key = key;
}

VaR M = new model ("ABC ");

$. Ajax ({
URL: '/demo. ashx ',
Type: 'post ',
Data: JSON. stringify (m ),
Contenttype: 'application/JSON; charset = utf8 ',
Cache: false,
Datatype: 'text ',
Success: function (data ){
Alert (data );
},
Error: function (xhr ){
Alert ("an error occurred. Please try again later:" + xhr. responsetext );
}
});
});

Demo. ashx:

    public class Demo : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World" + context.Request.Form["key"]);
}

public bool IsReusable
{
get
{
return false;
}
}
}

"Hello world" is displayed after running ":

You can change it to the following:

$. Ajax ({
URL: '/demo. ashx ',
Type: 'post ',
// Data: JSON. stringify (m ),
// Contenttype: 'application/JSON; charset = utf8 ',
Data: {key: "ABC "},
Cache: false,
Datatype: 'text ',
Success: function (data ){
Alert (data );
},
Error: function (xhr ){
Alert ("an error occurred. Please try again later:" + xhr. responsetext );
}
});

Does anyone know why?

ASP. NET JavaScript post JSON. stringifyartwl | Expert Level 6 | garden beans: 11082
Question: The FAQ function was launched at,. <>!

Favorite best answers

0

Use context. Request. inputstream to connect to it,

Data: {key: "ABC"}. This can only be used as a demo. How do you write large objects.
Harvest garden beans: 50 replies | small ai | cainiao Level 2 | garden beans: 223 |

I mainly want to figure out whyJSON. stringify formatting ParametersValue not obtained

Reply | artwl | garden bean: 11082 (Expert Level 6) |

You can use context. Request. inputstream to obtain the following information:

 

I just don't understand why context. Request. Form ["key"] cannot get the value.

Reply | artwl | garden bean: 11082 (Expert Level 6) |

@ Artwl: Follow up the result of JSON. stringify (m) to see what is different from {key: "ABC. After you get there, you can play with it and deserialize it.

Reply | xiao ai | garden bean: 223 (cainiao Level 2) |

@ Artwl...

Reply | xiao ai | garden bean: 223 (cainiao Level 2) |

@ Xiao ai: Haha, line, score

Reply | artwl | garden bean: 11082 (Expert Level 6) |

 

Loading editor... the answer is accepted. You can get the reward garden beans. Upload images Loading editor...Fuwen District

Toolbar

Undo (ctrl z) Redo (CTRL y)  
Select text color

 
Bytes
Select background color

 
Bytes
Reference   Bold (ctrl B) Italic (ctrl I) Underline (ctrl u) Strikethrough  
Unordered number Bytes
Sequential Number Bytes
  Left aligned Center alignment Right alignment Reduce indentation Increase indentation Clear format   Insert/edit Link Clear link Insert/edit Image Edit HTML source code Switch to full screen mode Insert Code (recommended)

 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.