VS General Handler *.ashx can handle many things.

Source: Internet
Author: User

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.

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.