Submit AJAX to the current page for processing

Source: Internet
Author: User

Previously, I wrote an ajax application to submit it to the ashx General handler! Then a new ashx page will be created! You can also submit it to the current page to avoid creating a new ashx! However, submitting to this page is equivalent to submitting the tag and will do some useless operations! Because IsPostBack does not work for ajax requests! Which page does ajax submit! I am not very clear! If you are interested, you can go to Baidu and google to find the answer!

Default. aspx page

<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "Default. aspx. cs" Inherits = "Test. _ Default" %> <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
Default. aspx background
 
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace Test{    public partial class _Default : System.Web.UI.Page    {        protected void Page_Load(object sender, EventArgs e)        {            if (IsPostBack) return;            if (!string.IsNullOrEmpty(Request.QueryString["ajax"]))            {                string name = "hao'jiang\"fesd";                string json = "{Id:1,Name:\"" + name.Replace("'", "%27").Replace("\"", "%22") + "\",Sex:\"male\"}";
// Hey, the above can be used: string json = "{Id: 1, Name: \" "+ Server. urlEncode (name) + "\", Sex: \ "male \"} "; Response. write (json );
/** Note: If the page submitted by ajax is aspx. * Response. end (); otherwise, you will print out the characters you need, and then print the HTML of the page *. I didn't know it before and didn't execute Response. end (), xmlhttprequest. responseText: * it still needs to be truncated! * Remember to call Response. End () every time. If you are interested, comment out Response. End (); and try again! **/Response. End ();
                //Response.End();            }           }            }}
 
 

Technorati label: ajax submit
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.