Why would I be getting a "missing ) after argument list" error?
I am working on an AJAX system to submit a form, but I can't even get my JavaScript to load, the Firebug report is below.
missing ) after argument list
else if( httpRequest.responseText == 'already logged in' )\n
I poked around the internet and SO, but all I found was errors in quoting. (Example, Another Example). I don't have anything misquoted, so I really don't see what is going on. More of my code is below.
(Some unrelated function calls to开发者_运维技巧 remove loading messages are removed.)if(httpRequest.responseText != "failure") // Works fine!
{
document.getElementById("result").innerHTML = "[Success message]";
setTimeout("2000", function(){ window.location.assign("[link to page]");
}
else if(httpRequest.responseText == 'already logged in') // Similar to above, but fails
{
document.getElementById("result").innerHTML = "[error message]";
}
else
{
document.getElementById("result").innerHTML = "[error message]";
}
Might anyone know why this error is called?
(For more members, it might be useful to outline what things cause this error, which would allow this page to work with other code)the line
setTimeout("2000", function(){ window.location.assign("[link to page]");
misses a })
causing the next line to fail (the whole syntax is wrong anyway:)
it should be
setTimeout (function(){ window.location.assign("[link to page]") } , 2000 );
setTimeout
takes a function as the first parameter and an integer as the second one.
more here
If you split your code up a bit more you see the problem:
setTimeout("2000", function()
{
window.location.assign("[link to page]");
So you are missing a } and a );
setTimeout(function()
{
window.location.assign("[link to page]");
},2000);
Edit: The order of the arguments is wrong as well like Caspar pointed out.
setTimeout("2000", function(){ window.location.assign("[link to page]");
should be
setTimeout("2000", function(){ window.location.assign("[link to page]");});
You are missing the });
here
setTimeout("2000", function(){ window.location.assign("[link to page]");
should be
setTimeout("2000", function(){ window.location.assign("[link to page]"); });
精彩评论