它不是在今天早些时候给出错误的,但是现在每次我上传文件时Unexpected number in JSON at position 161我查看了文件上传JSON,并了解到该文件传递了非法的0: { "ftype":"file", "meta":"prem-sal2.jpg", "fname":"screenshot1", "id":"392", "epn":"63", "action":"updategamefiles", "file":{ "name":"prem-sal2.jpg", "type":"image/jpeg", "tmp_name":"/tmp/phpxPZNCL", "error":0, "size":968969 } }这是选择文件的javascript:else if (fieldclass[1].indexOf("screenshot") >= 0) { ftype = 'file'; document.getElementsByClassName(fname)[0].getElementsByTagName('label')[0].innerHTML = 'Loading'; meta = this.files[0].name; file = this.files[0]; if( file.type === "image/jpg" || file.type === "image/png" || file.type === "image/gif" || file.type === "image/jpeg") { extension = true; } }因此,如何避免在文件JSON中收到该错误:0?嗯,忘了添加Ajax请求: if (extension === true) { var data = new FormData(); data.append('file', file); data.append('ftype', ftype); data.append('meta', meta); data.append('fname', fname); data.append('id', id); data.append('epn', epn); data.append('action', 'updategamefiles'); var value = jQuery.ajax({ data : data, type: 'POST', url: ajaxurl, cache: false, processData: false, // Don't process the files contentType: false, // Set content type to false as jQuery will tell the server its a query string request dataType: 'json',
添加回答
举报
0/150
提交
取消