php - JSON ERROR for uploader -
i have been struggling json error time now. code have uploading is,
}, addfile: function ( e ) { if (e.files) caller = e; else { caller = e.target; if (this.lastvalue==e.target.value) {return ;} } appendfile = function ( file ) { fname = !file.value ? file.name : file.value; fname = fname.split('\\'); fname = fname[fname.length-1]; fileitem = $('<div/>', { "class": "fileitem " }); delbtn = $('<div/>', {"class": "delete"}).html('<b>remove</b>'); fileitem.append(delbtn); fileitem.append($('<div/>', { "class": "progress", "style": "width:0%" })); fileitem.append($('<i/>', { "style": "position:relative;z-index:1;" }).html(fname)); this.filelistdiv.append(fileitem); delbtn.bind('click',{'fileitem':fileitem,'file':file,'fname':fname,'_this':this},function (event) { internal.filecount--; event.data.fileitem.remove(); removeitem = event.data.file; event.data._this.files.items = jquery.grep(event.data._this.files.items, function(value) { homecoming value != removeitem; }); if (event.data._this.files.items.length==[]) event.data._this.info.show(); if (event.data._this.ftext) event.data._this.ftext.val('deleted:' + event.data.fname); }); } if ((caller.files)&&(new xmlhttprequest().upload!=null)) { this.files.modern=true; (i=0;i<caller.files.length;i++) { file = caller.files[i]; if (this.checkext (file.name)) { if (internal.filecount<this.settings.maxfilecount || this.settings.maxfilecount==-1) { if (file.size<this.settings.maxfilesize || this.settings.maxfilesize==-1) { internal.filecount++; if (this.info.is(":visible")) {this.info.hide();} this.files.items.push(file); $.proxy(appendfile,this)(file); l = this.files.items.length; ct = l==1?' file':' files'; this.ftext.val(l + ct + ' added.'); } else alert('maximum file size: ' + this.settings.maxfilesize+' bytes.'); } else {alert('you cant upload more ' + this.settings.maxfilecount+ ' files.');break;} }; } } else { if (this.checkext (caller.value)) { if (internal.filecount<this.settings.maxfilecount || this.settings.maxfilecount==-1) { internal.filecount++; if (this.info.is(":visible")) {this.info.hide();} this.lastvalue=caller.value; this.files.modern=false; this.files.items.push(caller); this.filefield = $( '<input/>', { 'class':'file', 'name':'file', 'type':'file', 'multiple':'true'} ).bind('change', $.proxy(this.addfile,this)).css({'opacity':1}); $(caller).after(this.filefield); $(caller).hide(); $.proxy(appendfile,this)(caller); } else alert('you cant upload more ' + this.settings.maxfilecount+ ' files.'); }} }, sendfiles: function () { if (this.files.items.length<1) { this.ftext.val('no files selected.'); return; } $('.delete').each(function (item) { $(this).hide(); }); disable = function ( elm ) { elm = $(elm); elm.die(); elm.removeclass('button'); elm.addclass('disabled'); }; this.filefield.die(); disable(this.submit); disable(!this.fakediv ? this.fileitem: this.fakediv.children()[1]); if (!(this.upinfodiv.is(":visible"))) {this.upinfodiv.slidedown('fast');} if (this.files.modern) { this.tsize( false ); $.proxy(this.uploadmodern,this)( this.files.items[0] ); } else { $.proxy(this.tsize,this)( true ); $.proxy(this.uploadstandart, this)( this.files.items[0] ); $(this.upframe).bind('load',$.proxy(function () { this.reply= this.upframe.contentwindow.document.body.innerhtml; seek { this.reply= $.parsejson(this.reply);} grab (err) {this.uploaderror( 'jsonerror' );}; if (this.reply.success) { if (this.nform) this.nform.remove(); $(this.filelistdiv.children('.fileitem')[this.current].children[1]).css({'width':"100%"}); fname = this.files.items[this.current].value.split('\\'); fname = fname[fname.length-1]; textholder = this.settings.showlinks? $('<a/>',{"href":this.reply.file}) : $('<span/>'); textholder.html(fname); $(this.filelistdiv.children('.fileitem')[this.current].children[2]).html(textholder); this.current++; if (this.files.items[this.current]) { this.uploadstandart(this.files.items[this.current]); } else { this.alldone(); if ($.browser.msie) { $(this.upframe).unbind('load'); this.nform = $('<form/>',{'target':'upframe','action':'about:blank'}).hide(); this.filelistdiv.append(this.nform); this.nform.submit(); } } } else this.uploaderror( 'customerror' ); },this)); } }, tsize: function ( countonly ) { this.filecount = this.files.items.length; if (countonly) return; $(this.files.items).each($.proxy(function (i) { this.totalsize=this.files.items[i].size+this.totalsize; },this)); this.totalsize = (this.totalsize/1024).tofixed(); }, uploadprogress: function ( evt ) { percent = ((evt.loaded * 100) / evt.total).tofixed(); loaded = (evt.loaded/1024).tofixed(); total = (evt.total/1024).tofixed(); this.filepro.html("current file: "+percent+"% "+loaded+"kb/"+total+"kb"); this.totalpro.html('total: '+(this.current+1)+'/'+this.filecount+' files '+((this.totalloaded+evt.loaded)/1024).tofixed()+'/'+this.totalsize+'kb'); $(this.filelistdiv.children('.fileitem')[this.current].children[1]).css({'width':percent + "%"}); }, uploadfinished: function ( evt ) { percent = ((evt.loaded * 100) / evt.total).tofixed(); loaded = (evt.loaded/1024).tofixed(); total = (evt.total/1024).tofixed(); this.totalloaded = this.totalloaded+evt.total; this.filepro.html("current file: 100% "+total+"kb/"+total+"kb"); this.totalpro.html('total: '+(this.current+1)+'/'+this.filecount+' files '+(this.totalloaded/1024).tofixed()+'/'+this.totalsize+'kb') $(this.filelistdiv.children('.fileitem')[this.current].children[1]).css({'width':"100%"}); }, alldone: function () { this.upinfodiv.html('<h2>uploaded!</h2>').addclass('result').css({backgroundcolor:"#cdeb8b"}); this.settings.oncomplete(); }, uploaderror: function ( errortype ) { this.upinfodiv.html('<h2>upload failed</h2>').addclass('result').css({backgroundcolor:"#b02b2c",color:'white'}); $(this.filelistdiv.children('.fileitem')[this.current].children[1]).css({'width': "100%",backgroundcolor:"#b02b2c"}); switch ( errortype ) { case 'statuserror': response = '<b> bad response: '+this.xhr.status+' '+this.xhr.statustext+' </b>'; break; case 'customerror': response = '<b> server error: '+this.reply.details+' </b>'; break; case 'jsonerror': response = "<b>server returned invalid json response.</b>"; break; case 'filematcherror': response = '<b> file sent , file received on server dont match. </b>'; break; default : response = '<b> upload failed.</b>'; break; } this.upinfodiv.append(response); this.settings.onerror( response); }, uploadmodern: function ( file ) { if (file !== null) { this.xhr = new xmlhttprequest(); this.xhr.upload.addeventlistener("progress", $.proxy(this.uploadprogress,this) , false); this.xhr.upload.addeventlistener("load", $.proxy(this.uploadfinished,this) , false); this.xhr.upload.addeventlistener("error", $.proxy(this.uploaderror,this), false); this.xhr.open("post", this.settings.target+'?'+$.param(this.settings.data)); this.xhr.setrequestheader("if-modified-since", "mon, 26 jul 1997 05:00:00 gmt"); this.xhr.setrequestheader("cache-control", "no-cache"); this.xhr.setrequestheader("x-requested-with", "xmlhttprequest"); this.xhr.setrequestheader("x-file-name", file.name); this.xhr.setrequestheader("x-file-size", file.size); this.xhr.setrequestheader("content-type", "multipart/form-data"); this.xhr.onreadystatechange = $.proxy(function () { if (this.xhr.readystate==4) { if (this.xhr.status<400 && this.xhr.status>=200) { seek { this.reply= $.parsejson(this.xhr.responsetext);} grab (err) {this.uploaderror( 'jsonerror' );}; if (this.reply.success) { textholder = this.settings.showlinks? $('<a/>',{"href":this.reply.file}) : $('<span/>'); textholder.html(fname); $(this.filelistdiv.children('.fileitem')[this.current].children[2]).html(textholder); this.current++; if (this.files.items[this.current]) {this.uploadmodern(this.files.items[this.current]);} else this.alldone(); } else this.uploaderror( 'customerror' ); } else this.uploaderror( 'statuserror' ); } },this); if (file.getasbinary != undefined) { this.xhr.sendasbinary(file.getasbinary(file)); //mozilla case } else { this.xhr.send(file); //webkit case } }
}, have checked phpconfig countless times , looks perfect. have updated vps current versions , still nil prepare this. there way can implement like,
$.ajaxsetup({
timeout: 7000
to edit timeout of server? info valuable. give thanks time.
to reply question seem inquire in lastly line: no, can't alter server's scripting timeout browser.
php ajax json
No comments:
Post a Comment