I'm trying to upload a file using $.ajaxFileUpload. My server script is returning a json object eg.
{"imgName": "test.jpg", "imgUrl": "/uploadtest/images/profile/sam.jpg"}
When I check in firefox it shows the correct response. Json is also received. But still I'm getting an error in alert:
SyntaxError: missing } in XML expression
I couldn't understand why this error is shown up. Also in firebug Json object is shown correctly.
<script type='text/javascript' src='/js/ajaxfileupload.js'></script>
<script type='text/javascript'>
function doFileUpload(){
$("#loading")
.ajaxStart(function(){
$(this).show();
})
.ajaxComplete(function(){
$(this).hide();
});
$.ajaxFileUpload(
{
url:'/json/image/upload.html?action=saveImage&nameSpace=tot',
secureuri:false,
fileElementId:'imgFile',
dataType: 'json',
success: function (data, status){
alert("Success: "+data.imgUrl);
},
error: function (data, status, e){
alert("Error: "+e+"---URL: "+data.imgUrl);
}
}
)
}
</script>
.... ....
<div>
<strong>Upload Images:</strong><br>
<input type='file' name='imgFile' id='imgFile'>
<img src='/images/loading.gif' id='loading' height='60px' width='60px' style='display:none'>
<br><button name='upload' id='upload' onclick='return doFileUpload();'>Upload</button>
</div>
Anyone can tell me what's the reason for the Error?