简体   繁体   中英

Unexpected Identifier Error

I'm not sure why my code won't run.

Here is my JavaScript code:

fuction update(id, value){
    xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange=function(){
        if(xmlhttp.readyState==4 && xmlhttp.status == 200){
            document.getElementById("response").innerHTML=xmlhttp.responseText;
        }else{
            document.getElementById("response").innerHTML=
                                "AJAX Failed: " + xmlhttp.status;
        }
    }

    xmlhttp.open("GET","updatevis.php?id="+id+"&value="+value);
    document.getElementById("response").innerHTML="Sending Ajax Request";
    xmlhttp.send();
}

This is my HTML form code:

<input type="checkbox" name="visible" id="'.$id.'" checked="'.$checked.'" onchange="update('.$id.', '.$visible.')" />

The id would be anything from 1-whatever its auto increment, visible is a int , either 1 or 0 Checked is just my code to have it start checked or not

I have already run this code through chrome and Firefox, chrome gave my two errors a Unexpected identifier on line 5 (the line where I define the function) and a ReferenceError saying the function is not defined, on line 30 (the checkbox one)

You've miss-spelt function on the first line as fuction . Change this and everything should work as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM