Using the plug-in ajaxfileupload to upload files through Ajax, an error occurred in Firefox

Source: Internet
Author: User

In the past, the website had to implement an online file preview function, in which Ajax was used for background management. I am using a jquery plug-in ajaxfileupload. js
Today, my colleague suddenly reported an error (we used Firefox browsers before, and then I asked her to use other browsers without any problems). I tried it and made a mistake. Alertsyntaxerror: missing; before statementerror this should be a JS syntax error. I remember this error, but I forgot how to solve it later (of course, it may be that I remember it wrong ).
Part of the Code for calling ajaxfileupload to upload is as follows:

1 $. ajaxfileupload
2 (
3 {
4 URL: 'EB _ price. php? '+ Parm,
5 secureuri: false,
6 fileelementid: 'f _ file ',
7 datatype: 'json ',
8 success: function (data, status)
9 {
10 fun (data)
11 },
12 error: function (data, status, E)
13 {
14 alert (E + status) // product;
15
16}
17}
18 );

After analysis, jquery. uploadhttpdata (XML, S. datatype) is called. An exception is thrown due to a syntax error.

View code

 1  try {
2 status = isTimeout != "timeout" ? "success" : "error";
3 // Make sure that the request was successful or notmodified
4 if ( status != "error" )
5 {
6 // process the data (runs the xml through httpData regardless of callback)
7 var data = jQuery.uploadHttpData( xml, s.dataType );
8 // If a local callback was specified, fire it and pass it the data
9 if ( s.success )
10 s.success( data, status );
11
12 // Fire the global callback
13 if( s.global )
14 jQuery.event.trigger( "ajaxSuccess", [xml, s] );
15 } else
16 jQuery.handleError(s, xml, status);
17 } catch(e)
18 {
19 status = "error";
20 jQuery.handleError(s, xml, status, e);
21 }

Because the data type to be returned is in datatype: 'json' format, the parsing of the JSON string is incorrect. Converts characters in JSON format to objects;

Uploadhttpdata: function (R, type ){
VaR DATA =! Type;
Bug (r); // bug is the console. Log () of the encapsulated firebug ();
Data = type = "XML" | data? R. responsexml: R. responsetext;
Bug (data );
// If the type is "script", Eval it in global context
If (type = "script ")
Jquery. globaleval (data );
// Get the JavaScript Object, if JSON is used.
If (type = "JSON ")
Eval ("Data =" + data );
// Evaluate scripts within HTML
If (type = "html ")
Jquery ("<div>" ).html (data). evalscripts ();

Return data;
}

Result output twice


We can see that the Second Bug (data); the content of data has a piece of HTML code, which is so nice. I was very familiar with this code and suddenly thought of it. It seems like the magic mirror plug-in of Firefox is embedded;

In the network panel of firebug, we can see that the returned data seems to be normal.

However, it was modified later.
Open a webpage and you can see the hidden DIV in firebug;

Now everything is clear,
The reason why my colleague used Firefox was okay was that the problem suddenly occurred because Firefox was upgraded two days ago. (It seems that you have not installed the magic mirror before. It will be installed automatically during this update. Previously, the magic mirror was disabled. After being upgraded to the Firefox Application Center, it became enabled. This is just my guess ).
In addition, this plug-in will certainly not embed code in every request. This code is related to the player that plays the video. It displays a frame around the player, prompting you to play it separately.
The reason why the plug-in is embedded in the results returned after Ajax upload is That Ajax in ajaxfileupload is not the usual Ajax. It only creates a hidden IFRAME, creates a Form file field, and submits the file to the server. Then, the content in IFRAME, that is, the result returned by the Web server, is processed and returned to the code that calls it.

Solution:

1. Change the browser. (Because this function is only used by our background staff, of course we can do this ^_^)

2. Uninstall the plug-in.

3. js determine whether the code exists. If any, replace it with an empty string;

However, the best way is not to modify the structure of the original webpage. It is possible to achieve the original effect without modifying the structure.

2011 8.19 after returning home last night, I visited the Firefox community. This is not just me. The code used to pop up the video will be inserted in the FCKeditor editor.
And replied: the problem has been fixed. Version 5.0.1 has been released-overspeed
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.