The most common Ajax Chinese garbled solution.

Source: Internet
Author: User

There are many messy solutions on the Internet, such as setting up Web. config.

Thanks to the monkey for telling me the most common method is the front-end JS Chinese code escape () and backend decoding server. urldecode ()

In addition, if the advanced save option of the webpage is not UTF-8, change it. I have not tried any other encoding. In short, this encoding is successful.

Front-end:

  1. <% @ Page Language = "C #" autoeventwireup = "true" codefile = "ajaxluanma. aspx. cs" inherits = "testxc_ajaxluanma" %>
  2. <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <HTML xmlns = "http://www.w3.org/1999/xhtml">
  4. <Head runat = "server">
  5. <Title> Ajax Garbled text </title>
  6. <SCRIPT type = "text/JavaScript">
  7. // Enter the column number, column name, And monthnum to update the database.
  8. // If monthnum is "null", it indicates that the temporary table is to be updated.
  9. // If monthnum is not empty, update the template table based on the month and column number.
  10. Function callserver (colname, Col, monthnum)
  11. {
  12. Arg = escape (colname) + '|' + escape (COL) + '|' + escape (monthnum );
  13. <% = Clientscript. getcallbackeventreference (this, "Arg", "oncallback", null) %>;
  14. }
  15. // Callback function, prompt.
  16. Function oncallback (result, context)
  17. {
  18. Alert (Unescape (result ));
  19. }
  20. </SCRIPT>
  21. </Head>
  22. <Body>
  23. <Form ID = "form1" runat = "server">
  24. <Div>
  25. <Input type = "button" value = "OK" onclick = 'callserver ("column name", "column number", "blank"); '/>
  26. </Div>
  27. </Form>
  28. </Body>
  29. </Html>

Background:

  1. Using system;
  2. Using system. Data;
  3. Using system. configuration;
  4. Using system. collections;
  5. Using system. Web;
  6. Using system. Web. Security;
  7. Using system. Web. UI;
  8. Using system. Web. UI. webcontrols;
  9. Using system. Web. UI. webcontrols. webparts;
  10. Using system. Web. UI. htmlcontrols;
  11. Public partial class testxc_ajaxluanma: system. Web. UI. Page, system. Web. UI. icallbackeventhandler
  12. {
  13. Private string result;
  14. Protected void page_load (Object sender, eventargs E)
  15. {
  16. }
  17. // Handle callback events
  18. Public void raisecallbackevent (string eventargument) // The parameter is a string passed from the foreground.
  19. {
  20. String [] ARGs = eventargument. Split ('| ');
  21. // Execute the business logic
  22. String arg0 = server. urldecode (ARGs [0]);
  23. String arg1 = server. urldecode (ARGs [1]);
  24. String arg2 = server. urldecode (ARGs [2]);
  25. If (arg2 = "null ")
  26. Result = "Update temporary table:" + arg0 + "and" + arg1;
  27. Else
  28. Result = "Update template table:" + arg0 + "and" + arg1;
  29. }
  30. // Return the callback result
  31. Public String getcallbackresult ()
  32. {
  33. Return result;
  34. }
  35. }

End

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.