我想传递其他参数和文件以保存在数据库中。当我把代码放到这些变量并保存在数据库中它给我警告“SyntaxError:语法错误”... 这是我的代码
$.ajaxFileUpload
({
url:'popup/doc_mydeal.php',
secureuri:false,
fileElementId:'deals_documents',
dataType: 'json',
data:{rand_key: $('#rand_key').val(), document_name: $('#document_name').val()},
success: function (data, status)
{
if(typeof(data.error) != 'undefined')
{
if(data.error != '')
{
alert(data.error);
}
}
},
error: function (data, status, e)
{
alert(e);
}
})
现在在doc_mydeal.php
$tempFile = $_FILES['deals_documents']['tmp_name'];
$targetFile=$path.$_REQUEST['rand_key'].basename($_FILES['deals_documents']['name']);
move_uploaded_file($tempFile,$targetFile);
这里是要保存在数据库中的mysql查询
答案 0 :(得分:2)
当您在jQuery AJAX调用的选项中指定dataType
json
时,您告诉代码服务器将返回有效的JSON。根据这些信息,jQuery将隐式地将响应文本解析为JSON,将结果对象作为回调函数的参数传递。
如果响应文本不是有效JSON,则解析将失败,而error
回调将被执行。正如评论中指出的那样,从PHP脚本返回的内容是无效的JSON。