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 background color |
Bytes |
|
Reference |
|
Bold (ctrl B) |
Italic (ctrl I) |
Underline (ctrl u) |
Strikethrough |
|
|
|
|
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) |
|
|
|
|