Javascript can';t使用firefox发布ajax日志

Javascript can';t使用firefox发布ajax日志,javascript,jquery,ajax,firefox,Javascript,Jquery,Ajax,Firefox,我想发布一篇关于使用jQueryAjax而不重新加载页面的文章,它在Chrome中运行良好,但在Firefox6.0中不起作用。下面是我的代码 <html> <head> <script type="text/javascript"> function save() { $('#myForm').submit(function(event){ event.preventDefault

我想发布一篇关于使用jQueryAjax而不重新加载页面的文章,它在Chrome中运行良好,但在Firefox6.0中不起作用。下面是我的代码

 <html>
    <head>
    <script type="text/javascript">
      function save()
      {
        $('#myForm').submit(function(event){
          event.preventDefault();
          $.ajax({
                   type:'POST',
                   url:'save.php',
                   data:$('#myForm').serialize(),
                   success:function(data)
                   {
                        alert('form submitted');
                   },
                   error:function()
                   {
                       alert('unable to submit');
                   }   
               });
          });
      }
    </script>
    </head> 
       <body>
             <form id="myForm" action=''>
                <input type="text" name="firstName">
                <input type="text" name="lastName">
                <input type="submit" id="submitForm" onclick="save(myForm);">
             </form>
       <body>
</html>

函数save()
{
$('#myForm')。提交(函数(事件){
event.preventDefault();
$.ajax({
类型:'POST',
url:'save.php',
数据:$('#myForm')。序列化(),
成功:功能(数据)
{
警报(“提交的表格”);
},
错误:函数()
{
警报(“无法提交”);
}   
});
});
}

任何帮助都将不胜感激。

您的FF缓存中必须有jQuery的缓存版本,因为我看不到您在页面上的任何地方包含jQuery

在head部分添加上述其他脚本:

<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>

您的FF缓存中必须有jQuery的缓存版本,因为我看不到您在页面的任何地方包含jQuery

在head部分添加上述其他脚本:

<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>


在标题部分包含
jQuery
库。

在标题部分包含
jQuery
库。

我建议您去掉
onclick
save()
,只需使用jQuery提交处理程序即可

 <!-- make sure you have doctype -->
 <!DOCTYPE html>
 <html>
    <head>
     <script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
    <script type="text/javascript">
      $(function(){
        $('#myForm').submit(function(event){
          event.preventDefault();
          $.ajax({
                   type:'POST',
                   url:'save.php',
                   data:$('#myForm').serialize(),
                   success:function(data)
                   {
                        alert('form submitted');
                   },
                   error:function()
                   {
                       alert('unable to submit');
                   }   
               });
          });
      });
    </script>
    </head> 
       <body>
             <form id="myForm" action=''>
                <input type="text" name="firstName">
                <input type="text" name="lastName">
                <input type="submit" id="submitForm"><!-- remove onclick -->
             </form>
       <body>
</html>

$(函数(){
$('#myForm')。提交(函数(事件){
event.preventDefault();
$.ajax({
类型:'POST',
url:'save.php',
数据:$('#myForm')。序列化(),
成功:功能(数据)
{
警报(“提交的表格”);
},
错误:函数()
{
警报(“无法提交”);
}   
});
});
});

确保同时包含jQuery.js,我建议您去掉
onclick
save()
,只使用jQuery提交处理程序

 <!-- make sure you have doctype -->
 <!DOCTYPE html>
 <html>
    <head>
     <script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
    <script type="text/javascript">
      $(function(){
        $('#myForm').submit(function(event){
          event.preventDefault();
          $.ajax({
                   type:'POST',
                   url:'save.php',
                   data:$('#myForm').serialize(),
                   success:function(data)
                   {
                        alert('form submitted');
                   },
                   error:function()
                   {
                       alert('unable to submit');
                   }   
               });
          });
      });
    </script>
    </head> 
       <body>
             <form id="myForm" action=''>
                <input type="text" name="firstName">
                <input type="text" name="lastName">
                <input type="submit" id="submitForm"><!-- remove onclick -->
             </form>
       <body>
</html>

$(函数(){
$('#myForm')。提交(函数(事件){
event.preventDefault();
$.ajax({
类型:'POST',
url:'save.php',
数据:$('#myForm')。序列化(),
成功:功能(数据)
{
警报(“提交的表格”);
},
错误:函数()
{
警报(“无法提交”);
}   
});
});
});

确保还包括jQuery.js

他必须在FF缓存中有jQuery的缓存版本。如果页面没有脚本标记,则不能使用缓存版本。浏览器并没有那个么聪明抱歉,我并没有在这里写它,但在我的代码中,我包含了Jquery。我完全同意@jones看到charlietfl的答案。他必须在FF缓存中有jQuery的缓存版本。如果page没有脚本标记,则无法使用缓存版本。浏览器并没有那个么聪明抱歉,我并没有在这里写它,但在我的代码中,我包含了Jquery。我完全同意@琼斯看到了查理的答案。