进行ajax测试,报这个错误,代码检测无误,然后就是查了相关文档
发现是符号错误,eclipse识别中文符号,就会报这个错误,而且eclipse的js里需要写冒号结尾,附个代码.
1 <body> 2 <font size="24px" color="red">当前时 间:${requestScope.nowStr}</font> 3 <br /> 4 <input id="buttonID" type="button" value="点击这里实现" /> 5 6 <script type="text/javascript"> 7 function createAjax() { 8 var ajax = null; 9 try { 10 ajax = new ActiveXObject("microsoft.xmlhttp"); 11 } catch (e1) { 12 try { 13 ajax = new XMLHttpRequest(); 14 } catch (e2) { 15 alert("换一个浏览器吧!"); 16 } 17 } 18 return ajax; 19 } 20 </script> 21 22 <script type="text/javascript"> 23 document.getElementById("buttonID").onclick = function() { 24 var ajax = createAjax(); 25 if (ajax != null) { 26 alert("succeess"); 27 } else { 28 alert("unsuccess"); 29 } 30 }; 31 </script> 32 </body>