使用jquery或js读取大文本文件(24mb)

时间:2015-03-03 05:26:15

标签: javascript jquery

        // Create Reader.
        var xmlFile = document.getElementById( 'xmlFile' ).files[0];
        var reader = new FileReader();
        reader.readAsText( xmlFile );
        reader.onload = function( event )
        {
            var XMLData = event.target.result;
            alert(XMLData);

            jQuery.ajax
            ({
                url: ajaxurl,
                type: "POST",
                data:   {
                            action: 'upload_products',
                            XMLData: XMLData
                },
                success: function( data )
                {
                },
                error: function( data )
                {
                }
            });
        };

示例文本文件:其中包含大量产品。

    <?xml version="1.0"?>
    <TABLE-RECORDS>
      <EXPORT-RECORDS>
        <!-- product 1 -->
        <PRODUCT>
          <PRODUCTS_NAME>Panasonic Super Heavy Duty Battery AA - 4 Pack</PRODUCTS_NAME>
          <PRODUCTS_DESCRIPTION>fully functional whenever you need them.</PRODUCTS_DESCRIPTION>
          <PRODUCTS_IMAGE>1019.jpg</PRODUCTS_IMAGE>
          <PRODUCTS_PRICE>1.90</PRODUCTS_PRICE>
          <PRODUCTS_MODEL>1019</PRODUCTS_MODEL>
          <ITEM_BRANDNAME>Panasonic</ITEM_BRANDNAME>
          <ITEM_UPC>073096500235</ITEM_UPC>
          <ITEM_HEIGHT>0.500</ITEM_HEIGHT>
          <ITEM_LENGTH>4.250</ITEM_LENGTH>
          <ITEM_DIAMETER>3.375</ITEM_DIAMETER>
          <PRODUCTS_WEIGHT>0.16</PRODUCTS_WEIGHT>
          <MANUFACTURERS_NAME>Utm distributing</MANUFACTURERS_NAME>
          <ITEM_VENDOR_NUMBER>UM-3NPA/4B</ITEM_VENDOR_NUMBER>
          <DATE_RECIEVED>0000-00-00 00:00:00</DATE_RECIEVED>
          <PROP_PACKAGING>Blister Card</PROP_PACKAGING>
          <PRODUCT_CLASS>BAT</PRODUCT_CLASS>
          <PRODUCTS_TYPE>Batteries</PRODUCTS_TYPE>
        </PRODUCT>
        <!-- product 2 and so on -->
        <PRODUCT>
        ....
       </PRODUCT>
      </TABLE-RECORDS>
   </EXPORT-RECORDS>

这是我的代码。上面的代码适用于小文件,但对于较大的文件,它会崩溃。我怎么能读大文件?任何帮助将不胜感激。

0 个答案:

没有答案