Ajax generated stream file download and check box implementation

Source: Internet
Author: User

jquery's Ajax functions return type only XML, text, JSON, HTML and other types, there is no "stream" type, so we want to implement Ajax download, can not use the corresponding Ajax functions for file download. But you can use JS to generate a form, use this form to submit parameters, and return the "stream" type of data. The page is not refreshed during the implementation process.

<th><inputtype= "checkbox"name= "title"ID= "Checkbox_all"/></th>{% for student in students%}<TR>       <TD><inputtype= "checkbox"name= "Student_name"ID= "boxes"value= "{{student.number}}"/></TD>
$ (' #checkbox_all '). Click (function () {                    varA = document.getElementsByTagName ("Input"); if(document.getElementById ("Checkbox_all"). Checked = =true) {                         for(vari = 0; i < a.length; i++)                            if(A[i].type = = "checkbox") a[i].checked =true; }                    Else {                         for(vari = 0; i < a.length; i++)                            if(A[i].type = = "checkbox") a[i].checked =false; }                }        );
$ (' #input_student '). Click (function () {                vararr =NewArray (); varSign = 0; varInputs = document.getElementsByTagName (' input ');//gets all the input tag objects.                  for(vari = 0; i < inputs.length; i++) {                    varobj =Inputs[i]; if(Obj.type = = ' checkbox ') {                        if(obj.checked = =true) { sign= 1; varLength =Arr.push (Obj.value); }                    }                }                if(sign = = 0)//No selected items{alert ("Please tick the data you want to download!" "); return; }                if(!confirm ("OK to download selected entries?") "))return; varForm = $ ("<form>"); Form.attr (' Style ', ' Display:none '); Form.attr (' Target ', '); Form.attr (' Method ', ' post '); Form.attr (' Action ', ' {% url ' teacher:downloadstu '%} '); varINPUT1 = $ (' <input> ')); Input1.attr (' type ', ' hidden '); Input1.attr (' Name ', ' number '); Input1.attr (' Value ', Arr.join ("&")); $(' Body '). append (form);                Form.append (INPUT1);                Form.submit ();                Form.remove (); });

If you submit more than one data, use a few more input.

Ajax generation stream file download and check box implementation

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.