插入mysql(使用codeigniter JSON)不起作用

时间:2014-07-29 17:03:25

标签: codeigniter

我正在使用codeigniter。当我向mysql插入一些数据时,它会给出错误:

Uncaught SyntaxError: Unexpected token < paintings.js:163
$.click.ajaxReq.onreadystatechange

我的.js是:

var target = document.getElementById('submitimage');
var spinner = new Spinner(opts).spin(target);


var url=config.base.concat("admin/painting/saveImage");
var fileId1 = document.getElementById('iconimage');
var fileId2 = document.getElementById('paintingimage');

var formObj = new FormData();
var file1=$('#iconimage').val();
var file2=$('#paintingimage').val();

var extension1 = file1.substr((file1.lastIndexOf('.') +1) );
var extension2 = file2.substr((file2.lastIndexOf('.') +1) );

formObj.append('iconimage', fileId1.files[0]);
formObj.append('paintingimage', fileId2.files[0]);

formObj.append('name',$('#name').val());
formObj.append('extension1',extension1);
formObj.append('extension2',extension2);

formObj.append('category',category);
formObj.append('color',color);
formObj.append('price',price);

formObj.append('error-check', true);
formObj.append('finish-check', true);

var ajaxReq;
try {

    ajaxReq = new XMLHttpRequest();

} catch (e) {

    try {
        ajaxReq = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {

        try {
            ajaxReq = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {
            alert("Your browser does not support image upload at this environment.");
            return false;
        }
    }
}// browser veryfication

ajaxReq.open('POST', url);
ajaxReq.setRequestHeader('Cache-Control', 'no-cache');
ajaxReq.send(formObj); 

ajaxReq.onreadystatechange=function() {
    if (ajaxReq.readyState==4 && ajaxReq.status==200) {
        spinner.stop();
        var a=ajaxReq.responseText;
        var jsonData=JSON.parse(a);

        if(jsonData.status == "success") {

            alert("Successfully Saved");
            $('div[class=errordiv]').each(function(){

                this.innerHTML='';
            });
            $(':input','#galleryform').not(':button, :submit, :reset, :hidden').val('').removeAttr('checked').removeAttr('selected');

        } else {
            alert("ERROR:Some unexpected event has been occured. Please try again!");
        }
    }

}
}
}

0 个答案:

没有答案