Ajax Asynchronous commit

Source: Internet
Author: User

Need to introduce jquery scripts

1. Submission-side script

varEid = ' <%= str_eid%> '; varDate = ' <%= str_date%> '; varYear = ' <%= str_year%> '; varQuarter = ' <%= str_quarter%> '; varSSID = ' <%= str_ssid%> '; //Queue submission starts        varAjaxes = []; varXMLHTTP =function () {            varXHR =false; Try{XHR=NewActiveXObject ("Msxml2.xmlhttp"); }            Catch(e) {Try{XHR=NewActiveXObject ("Microsoft.XMLHTTP"); }                Catch(E1) {XHR=false; }            }            if(!XHR &&typeofXMLHttpRequest! = ' undefined ') {XHR=NewXMLHttpRequest (); }            returnXHR; }        varXHR =NewXMLHTTP ();//get the XMLHttpRequest instance object XHR        //Executeajax is the main function that performs Ajax        varExecuteajax =function () {            ////If the queue is empty, exit execution            if(!ajaxes.length)return; //setTimeout ("WaitTime ()", "a");            varoptions = Ajaxes[0]; if(XHR) {Xhr.open (Options.method, Options.url,true); Xhr.onreadystatechange=function () {                    if(Xhr.readystate = = = 4 && (xhr.status = = = | | xhr.status = = 304) {options.callback (Xhr.responsetext, Options.deptid, options.scid); //Delete the first request in a queueAjaxes.shift (); //If there is a request in the queue, the Executeajax function is then recursively executed until the queue is empty                        if(Ajaxes.length > 0) {Executeajax (); }                    }                }                if(Xhr.method = = = "POST") {Xhr.setrequestheader ("Content-type", "application/x-www-form-urlencoded"); } xhr.send (Options.data||NULL); }        }        //functions to add a queue        varAddajax =function(options) {Ajaxes.push (options); }        //the specific Operation        varSubmitonequestion =function(DeptID, SCID, Levelid, score) {            varurl = String.Format ("Mz_exam2operation.ashx?eid={0}&&date={1}&&year={2}&&quarter={3} &AMP;&AMP;SSID={4}&AMP;&AMP;DEPTID={5}&AMP;&AMP;SCID={6}&AMP;&AMP;LEVELID={7}&AMP;&AMP;SCORE={8} ", Eid, date, year, quarter, SSID, DeptID, SCID, Levelid, score); Addajax ({method:"GET", Url:url, Deptid:deptid, Scid:scid, callback:applydom}); //Start Execution QueueExecuteajax (); }        //Return Status        varApplydom =function(Reponsetext, DeptID, SCID) {//reloadnum ();            if(Reponsetext = = "Success") {                varCELL_RBTN1 = $ (' # ' + ' Cell_ ' + DeptID + ' _ ' + SCID + ' _rbtn1 '); varCELL_RBTN2 = $ (' # ' + ' Cell_ ' + DeptID + ' _ ' + SCID + ' _rbtn2 '); varCELL_RBTN3 = $ (' # ' + ' Cell_ ' + DeptID + ' _ ' + SCID + ' _rbtn3 '); varCell_score = $ (' [Id^=cell_ ' + DeptID + ' _ ' + SCID + ' _score] '); Cell_rbtn1.css (' Color ', ' #6bd553 '); Cell_rbtn2.css (' Color ', ' #6bd553 '); Cell_rbtn3.css (' Color ', ' #6bd553 '); //cell_score.css (' Color ', ' #6bd553 ');Cell_rbtn1.css (' FontWeight ', ' bold '); Cell_rbtn2.css (' FontWeight ', ' bold '); Cell_rbtn3.css (' FontWeight ', ' bold '); //cell_score.css (' fontweight ', ' bold ');cell_score.attr (' Isrequest ', ' 1 ');//whether there is a return value, 0 is not returned, and 1 is returned.             }        }        //end of queue submission        functionradiochanged (CNAME, Classno) {$ ("#" + CNAME). attr ("level"), Classno); varDeptID = Cname.split ('_') [1]; varSCID = Cname.split ('_') [2]; varLevelid =Classno; varScore = "0"; //Different types have different fractional segments            if(SCID >= 1 && SCID <= 4) {                Switch(Classno) { Case"1":                        $("#" + CNAME). Val ("15"); score = 15; Break;  Case"2":                        $("#" + CNAME). Val ("10"); Score = 10; Break;  Case"3":                        $("#" + CNAME). Val ("5"); Score = 5; Break; default:                        $("#" + CNAME). Val ("15"); score = 15; Break; }            }            Else                if(SCID >= 5 && SCID <= 8) {                    Switch(Classno) { Case"1":                            $("#" + CNAME). Val ("10"); Score = 10; Break;  Case"2":                            $("#" + CNAME). Val ("7"); Score = 7; Break;  Case"3":                            $("#" + CNAME). Val ("3"); Score = 3; Break; default:                            $("#" + CNAME). Val ("10"); Score = 10; Break; }                }            //added at any time to submit. submitonequestion (DeptID, SCID, Levelid, score); }

2. Receive-Side code

 Public voidProcessRequest (HttpContext context) {context. Response.ContentType="Text/plain"; String Str_eid= Context. request.querystring["Eid"].        ToString (); String str_date= Context. request.querystring["Date"].        ToString (); String Str_year= Context. request.querystring[" Year"].        ToString (); String Str_quarter= Context. request.querystring["Quarter"].        ToString (); String Str_ssid= Context. request.querystring["SSID"].        ToString (); String Str_deptid= Context. request.querystring["DeptID"].        ToString (); String Str_scid= Context. request.querystring["SCID"].        ToString (); String Str_levelid= Context. request.querystring["Levelid"].        ToString (); String Str_score= Context. request.querystring["score"].        ToString (); if(Submitonequestion (Str_eid, Str_date, Str_year, Str_quarter, Str_ssid, Str_deptid, Str_scid, Str_levelid, str_ Score)) {context. Response.ContentType="Text/plain"; Context. Response.Write ("Success"); }        Else{context. Response.ContentType="Text/plain"; Context. Response.Write ("failed"); } context. Response.Buffer=true; Context. Response.ExpiresAbsolute= DateTime.Now.AddDays (-1); Context. Response.Cache.SetExpires (DateTime.Now.AddDays (-1)); Context. Response.Expires=0; Context. Response.CacheControl="No-cache"; Context.    Response.Cache.SetNoStore (); }

Ajax Asynchronous commit

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.