These two days follow FAI to do the project.
Because my project was almost piled up with all sorts of repeating statements,
It's very cumbersome to maintain.
So I'm going to keep writing with his project.
Then came a question, that is, I asked FAI, is not a *.ashx can only deal with a thing,
Hui said no, you can use Ajax to put in the data when the first key value that set the same key but different values.
I thought for a long time and did not understand, then I came to the second genius to understand.
For example:
My Web page reads this:
<script type= "Text/javascript" >$ ("#button1"). Click (function () {$.ajax ( { type: "POST", url: "/ashx/a.ashx", async: ' true ', data: "key1=" + "first" + "A=" + "1" + "b = " + " 2 ", success: function (msg) { if (msg == "A1") { alert (" aaaaaaaaaaaaaaaaaa! "); } else if (msg == "A2") { alert (" bbbbbbbbbbbbbbbbbb! "); } ...... }, complete: function (data) { }, error: function (Xmlhttprequest, textstatus, thrownerror) { //window.location.reload () ; alert (Xmlhttprequest.status); alert (xmlhttprequest.readystate); alert (TextStatus); &Nbsp; alert (XMLHttpRequest.responseText ); }); </script > Then I wrote in A.ashx: Public void processrequest (httpcontext context) { if (context. request["Key1"] == "first") { //code blocks, various processing statements context. Response.Write ("A1"); } if (context. request["Key1"] == "second") { context. Response.Write ("A2"); } if (context. request["Key1"] == "third") { //code blocks, various processing statements context. Response.Write ("A3"); } ....... }
What I've been trying to figure out is, what if every AJAX statement has the same key value, and then it's messy?
In the end I want to understand, is not.
Because as long as I pass the first key value of Ajax, he can only go into one of the if inside execution,
The other if he is not going to go in, this kind of can only be executed in accordance with his code block, not mess up!
VS General Handler *.ashx can handle many things.