5

I'm new to jQuery and Ajax and I have run into a problem. Im getting the error on my console that:

NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument @ http://localhost
/jquery.js:7065

Why am I receiving this error?

this is the code Im Using:

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);
        }
    });
    }

Im waiting for your replies.

PS: I Did search the forum but did not get what i want, so if i missed something, sorry in advance.

6
  • 1
    first of all class is a reserved word..change this line var class1 = document.form1.class
    – coolguy
    Commented Sep 18, 2012 at 8:44
  • 1
    first of all what you trying to do is wrong... you can't upload file using ajax.... if you want ajax like file upload then you have to use iframe.
    – Surace
    Commented Sep 18, 2012 at 8:47
  • 1
    second of all why you trying to pass dom object elements to the server... you suppose to pass their values...
    – Surace
    Commented Sep 18, 2012 at 8:54
  • how will i pass their values?
    – echo_salik
    Commented Sep 18, 2012 at 9:04
  • @ubercooluk please see again... var is class1...
    – echo_salik
    Commented Sep 18, 2012 at 9:05

4 Answers 4

8

I think the problem is you are trying to pass complete objects to the JSON. You should use values instead of objects. For example, replace:

var subject = document.form1.subject;

with:

var subject = document.form1.subject.value;
0

Use this , i guess bracket mismatch --

    $.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);
        }
    );
1
  • 1
    @ZackValentine change class in your form as class is a reserved keyword to something like this myclass and then use it like -- var class1 = document.form1.myclass;
    – swapnesh
    Commented Sep 18, 2012 at 9:08
0

I ran into the same error, but my problem was different.

Turns out, I was passing a parameter in the ajax call that wasn't present in my DOM at all.

In @ZackValentine-s case (or for someone reading this in the future), please check the value of all the data items you are about to pass to the ajax call, BEFORE the actual call itself.

0

We had the same error.

Upgraded to the latest version of JQuery and problem solved.

This one seems to work for some people seen that solution here too

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.