Javascript 在服务器上上载后出现ajaxFileUpload语法错误

Javascript 在服务器上上载后出现ajaxFileUpload语法错误,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我在ajax上传的codeigniter脚本中使用ajaxFileUpload jquery插件 然而,我不知道这是否是一个浏览器相关的错误。 我在本地开发(localhost),脚本工作得很好,但是,当我在一个带有完全相同的软件(PHP-自行开发)的实时站点上使用脚本时,我得到了以下错误“SyntaxError:syntax error eval(“data=“+data”);” 有没有可能是因为邮件的延迟导致的 请帮忙 ajaxFileUpload.js代码: jQuery.extend({

我在ajax上传的codeigniter脚本中使用ajaxFileUpload jquery插件

然而,我不知道这是否是一个浏览器相关的错误。 我在本地开发(localhost),脚本工作得很好,但是,当我在一个带有完全相同的软件(PHP-自行开发)的实时站点上使用脚本时,我得到了以下错误
“SyntaxError:syntax error eval(“data=“+data”);”

有没有可能是因为邮件的延迟导致的

请帮忙

ajaxFileUpload.js代码:

jQuery.extend({


    createUploadIframe: function(id, uri)
    {
            //create frame
            var frameId = 'jUploadFrame' + id;
            var iframeHtml = '<iframe id="' + frameId + '" name="' + frameId + '" style="position:absolute; top:-9999px; left:-9999px"';
            if(window.ActiveXObject)
            {
                if(typeof uri== 'boolean'){
                    iframeHtml += ' src="' + 'javascript:false' + '"';

                }
                else if(typeof uri== 'string'){
                    iframeHtml += ' src="' + uri + '"';

                }   
            }
            iframeHtml += ' />';
            jQuery(iframeHtml).appendTo(document.body);

            return jQuery('#' + frameId).get(0);            
    },
    createUploadForm: function(id, fileElementId, data)
    {
        //create form   
        var formId = 'jUploadForm' + id;
        var fileId = 'jUploadFile' + id;
        var form = jQuery('<form  action="" method="POST" name="' + formId + '" id="' + formId + '" enctype="multipart/form-data"></form>');    
        if(data)
        {
            for(var i in data)
            {
                jQuery('<input type="hidden" name="' + i + '" value="' + data[i] + '" />').appendTo(form);
            }           
        }       
        var oldElement = jQuery('#' + fileElementId);
        var newElement = jQuery(oldElement).clone();
        jQuery(oldElement).attr('id', fileId);
        jQuery(oldElement).before(newElement);
        jQuery(oldElement).appendTo(form);



        //set attributes
        jQuery(form).css('position', 'absolute');
        jQuery(form).css('top', '-1200px');
        jQuery(form).css('left', '-1200px');
        jQuery(form).appendTo('body');      
        return form;
    },

    ajaxFileUpload: function(s) {
        // TODO introduce global settings, allowing the client to modify them for all requests, not only timeout        
        s = jQuery.extend({}, jQuery.ajaxSettings, s);
        var id = new Date().getTime()        
        var form = jQuery.createUploadForm(id, s.fileElementId, (typeof(s.data)=='undefined'?false:s.data));
        var io = jQuery.createUploadIframe(id, s.secureuri);
        var frameId = 'jUploadFrame' + id;
        var formId = 'jUploadForm' + id;        
        // Watch for a new set of requests
        if ( s.global && ! jQuery.active++ )
        {
            jQuery.event.trigger( "ajaxStart" );
        }            
        var requestDone = false;
        // Create the request object
        var xml = {}   
        if ( s.global )
            jQuery.event.trigger("ajaxSend", [xml, s]);
        // Wait for a response to come back
        var uploadCallback = function(isTimeout)
        {           
            var io = document.getElementById(frameId);
            try 
            {               
                if(io.contentWindow)
                {
                     xml.responseText = io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null;
                     xml.responseXML = io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document;

                }else if(io.contentDocument)
                {
                     xml.responseText = io.contentDocument.document.body?io.contentDocument.document.body.innerHTML:null;
                    xml.responseXML = io.contentDocument.document.XMLDocument?io.contentDocument.document.XMLDocument:io.contentDocument.document;
                }                       
            }catch(e)
            {
                jQuery.handleError(s, xml, null, e);
            }
            if ( xml || isTimeout == "timeout") 
            {               
                requestDone = true;
                var status;
                try {
                    status = isTimeout != "timeout" ? "success" : "error";
                    // Make sure that the request was successful or notmodified
                    if ( status != "error" )
                    {
                        // process the data (runs the xml through httpData regardless of callback)
                        var data = jQuery.uploadHttpData( xml, s.dataType );    
                        // If a local callback was specified, fire it and pass it the data
                        if ( s.success )
                            s.success( data, status );

                        // Fire the global callback
                        if( s.global )
                            jQuery.event.trigger( "ajaxSuccess", [xml, s] );
                    } else
                        jQuery.handleError(s, xml, status);
                } catch(e) 
                {
                    status = "error";
                    jQuery.handleError(s, xml, status, e);
                }

                // The request was completed
                if( s.global )
                    jQuery.event.trigger( "ajaxComplete", [xml, s] );

                // Handle the global AJAX counter
                if ( s.global && ! --jQuery.active )
                    jQuery.event.trigger( "ajaxStop" );

                // Process result
                if ( s.complete )
                    s.complete(xml, status);

                jQuery(io).unbind()

                setTimeout(function()
                                    {   try 
                                        {
                                            jQuery(io).remove();
                                            jQuery(form).remove();  

                                        } catch(e) 
                                        {
                                            jQuery.handleError(s, xml, null, e);
                                        }                                   

                                    }, 100)

                xml = null

            }
        }
        // Timeout checker
        if ( s.timeout > 0 ) 
        {
            setTimeout(function(){
                // Check to see if the request is still happening
                if( !requestDone ) uploadCallback( "timeout" );
            }, s.timeout);
        }
        try 
        {

            var form = jQuery('#' + formId);
            jQuery(form).attr('action', s.url);
            jQuery(form).attr('method', 'POST');
            jQuery(form).attr('target', frameId);
            if(form.encoding)
            {
                jQuery(form).attr('encoding', 'multipart/form-data');               
            }
            else
            {   
                jQuery(form).attr('enctype', 'multipart/form-data');            
            }           
            jQuery(form).submit();

        } catch(e) 
        {           
            jQuery.handleError(s, xml, null, e);
        }

        jQuery('#' + frameId).load(uploadCallback   );
        return {abort: function () {}}; 

    },

    uploadHttpData: function( r, type ) {
        var data = !type;
        data = type == "xml" || data ? r.responseXML : r.responseText;
        // 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;
    }
})
jQuery.extend({
createUploadIframe:函数(id,uri)
{
//创建框架
var frameId='jUploadFrame'+id;
var iframeHtml='';
jQuery(iframeHtml).appendTo(document.body);
返回jQuery('#'+frameId).get(0);
},
createUploadForm:函数(id、fileElementId、数据)
{
//创建表单
变量formId='jUploadForm'+id;
var fileId='jUploadFile'+id;
var form=jQuery(“”);
如果(数据)
{
用于(数据中的var i)
{
jQuery(“”).附录(表格);
}           
}       
var oldElement=jQuery(“#”+fileElementId);
var newElement=jQuery(oldElement).clone();
jQuery(oldElement).attr('id',fileId);
jQuery(oldElement).before(newElement);
jQuery(oldElement).appendTo(form);
//设置属性
jQuery(form).css('position','absolute');
jQuery(form).css('top','-1200px');
jQuery(form).css('left','-1200px');
jQuery(form.appendTo('body');
申报表;
},
ajaxFileUpload:函数{
//TODO引入全局设置,允许客户端为所有请求修改它们,而不仅仅是超时
s=jQuery.extend({},jQuery.ajaxSettings,s);
var id=new Date().getTime()
var form=jQuery.createUploadForm(id,s.fileElementId,(typeof(s.data)='undefined'?false:s.data));
var io=jQuery.createUploadIframe(id,s.secureuri);
var frameId='jUploadFrame'+id;
变量formId='jUploadForm'+id;
//观察一组新的请求
if(s.global&&!jQuery.active++)
{
jQuery.event.trigger(“ajaxStart”);
}            
var requestDone=false;
//创建请求对象
var xml={}
国际单项体育联合会(s.global)
触发器(“ajaxSend”[xml,s]);
//等待回复
var uploadCallback=函数(isTimeout)
{           
var io=document.getElementById(frameId);
尝试
{               
如果(io.contentWindow)
{
xml.responseText=io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null;
xml.responseXML=io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document;
}else if(io.contentDocument)
{
xml.responseText=io.contentDocument.document.body?io.contentDocument.document.body.innerHTML:null;
xml.responseXML=io.contentDocument.document.XMLDocument?io.contentDocument.document.XMLDocument:io.contentDocument.document;
}                       
}捕获(e)
{
handleError(s,xml,null,e);
}
if(xml | | isTimeout==“超时”)
{               
requestDone=true;
var状态;
试一试{
状态=isTimeout!=“超时”?“成功”:“错误”;
//确保请求成功或未被修改
如果(状态!=“错误”)
{
//处理数据(通过httpData运行xml,而不考虑回调)
var data=jQuery.uploadHttpData(xml,s.dataType);
//如果指定了本地回调,则激发它并将数据传递给它
如果(s.成功)
s、 成功(数据、状态);
//启动全局回调
国际单项体育联合会(s.global)
触发器(“ajaxSuccess”,[xml,s]);
}否则
handleError(s、xml、status);
}捕获(e)
{
status=“error”;
handleError(s,xml,status,e);
}
//请求已完成
国际单项体育联合会(s.global)
触发器(“ajaxComplete”[xml,s]);
//处理全局AJAX计数器
if(s.global&&!--jQuery.active)
jQuery.event.trigger(“ajaxStop”);
//过程结果
如果(完成)
s、 完成(xml,状态);
jQuery(io).unbind()
setTimeout(函数()
{试试看
{
jQuery(io.remove();
jQuery(form.remove();
}捕获(e)
{
handleError(s,xml,null,e);
}                                   
}, 100)
xml=null
}
}
//超时检查器
如果(s.超时>0)
{
setTimeout(函数(){
//检查请求是否仍然存在
<?php 
class Upload extends CI_Controller
{
   public function __construct()
   {
      parent::__construct();
      //$this->load->model('files_model');
      //$this->load->database();
      $this->load->helper('url');
   }

   public function index()
   {
      $this->load->view('upload');
   }

   public function upload_file()
{
   $status = "";
   $msg = "";
   $file_element_name = 'userfile';

   if (empty($_POST['title']))
   {
      $status = "error";
      $msg = "Please enter a title";
   }

   if ($status != "error")
   {
      $config['upload_path'] = './files/';
      $config['allowed_types'] = 'gif|jpg|png|doc|txt';
      $config['max_size']  = 1024 * 8;
      $config['encrypt_name'] = TRUE;

      $this->load->library('upload', $config);

      if (!$this->upload->do_upload($file_element_name))
      {
         $status = 'error';
         $msg = $this->upload->display_errors('', '');
      }
      else
      {
         $data = $this->upload->data();
         //$file_id = $this->files_model->insert_file($data['file_name'], $_POST['title']);
         if(true)
         {
            $status = "success";
            $msg = "File successfully uploaded";
         }
         else
         {
            unlink($data['full_path']);
            $status = "error";
            $msg = "Something went wrong when saving the file, please try again.";
         }
      }
      @unlink($_FILES[$file_element_name]);
   }
   echo json_encode(array('status' => $status, 'msg' => $msg));
}
}
$(function() {
   $('#upload_file').submit(function(e) {
      e.preventDefault();
      $.ajaxFileUpload({
         url         :'./upload/upload_file/',
         secureuri      :false,
         fileElementId  :'userfile',
         dataType    : 'json',
         data        : {
            'title'           : $('#title').val()
         },
         success  : function (data, status)
         {
            if(data.status != 'error')
            {
               //$('#files').html('<p>Reloading files...</p>');
               //refresh_files();
               $('#title').val('');
            }
            alert(data.msg);
         }
      });
      return false;
   });
});