AJAX NS_ERROR_XPC_BAD_CONVERT_JS:无法转换JavaScript参数jquery.js:7065

ech*_*lik 5 php jquery

我是jQuery和Ajax的新手,我遇到了一个问题.我在我的控制台上得到错误:

NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument @ http://localhost
/jquery.js:7065
Run Code Online (Sandbox Code Playgroud)

为什么我收到此错误?

这是我使用的代码:

function upload_file(){
    var file = document.form1.file_upload;
    var date = document.form1.date_added;
    var author = document.form1.author;
    var user = document.form1.user;
    var semester = document.form1.semester;
    var class1 = document.form1.class;
    var subject = document.form1.subject;
    $.ajax({
        type:"get",
        url:"upload_file.php",
        data:{
        "file":file,
        "date":date,
        "author":author,
        "user":user,
        "semester":semester,
        "class":class1,
        "subject":subject
        },
        success:function(result){
        $("#result").html(result);
        }
    });
    }
Run Code Online (Sandbox Code Playgroud)

我在等你的回复.

PS:我在论坛上搜索但没有得到我想要的东西,所以如果我错过了什么,请提前抱歉.

小智 8

我认为问题是你试图将完整的对象传递给JSON.您应该使用值而不是对象.例如,替换:

var subject = document.form1.subject;
Run Code Online (Sandbox Code Playgroud)

有:

var subject = document.form1.subject.value;
Run Code Online (Sandbox Code Playgroud)


swa*_*esh 0

使用这个,我猜括号不匹配--

    $.ajax(
                 {
        type:"get",
        url:"upload_file.php",
        data:{
        "file":file,
        "date":date,
        "author":author,
        "user":user,
        "semester":semester,
        "class":class1,
        "subject":subject
        },
        success:function(result)
               {
        $("#result").html(result);
        }
    );
Run Code Online (Sandbox Code Playgroud)