语法错误:在ajaxFileUpload的jQuery插件语法错误 [英] SyntaxError: syntax error in ajaxFileUpload jquery plugin

查看:173
本文介绍了语法错误:在ajaxFileUpload的jQuery插件语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过其他参数与文件保存在database.when我把code让那些变量保存在数据库中也给我警惕语法错误:语法错误? 这里是我的code

i want to pass other parameters with file to save in database.when i put code to get those variables and save in database it give me alert "SyntaxError: syntax error"... here is my code

$.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

Now on 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查询保存在数据库中

and here is mysql query to save in database

推荐答案

在指定的dataType JSON 在为jQuery的AJAX的选项叫你告诉code。该服务器将返回有效JSON。基于这些信息jQuery将隐式解析响应文本为JSON,得到的对象传递的回调函数的参数。

When you specify a dataType of json in the options for the jQuery AJAX call you're telling the code that the server will be returning valid JSON. Based on this information jQuery will implicitly parse the response text as JSON, passing the resulting object as the argument of the callback function.

在该响应文本的不是的有效的JSON解析将失败,错误回调将被执行,而不是这样的。正如已经指出的评论,你从你的PHP脚本返回的是无效的JSON。

In the case that the response text isn't valid JSON the parse will fail and the error callback will be executed instead. As has been pointed out in the comments, what you're returning from your PHP script is invalid JSON.

这篇关于语法错误:在ajaxFileUpload的jQuery插件语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆