weixin_33682790 2015-09-13 20:28 采纳率: 0%
浏览 16

没有刷新的Ajax发布

I've this simply code in status.php:

<script type="text/javascript">  
    $(document).ready(function() {  
        $("form#iscrizione").submit(function(){   
            var ordine = $("#ordine").val();  
            var cognome = $("#cognome").val();
            $.ajax({  
                type: "POST",
                url: "http://****/new/action.php",  
                data: "cognome=" + cognome + "&ordine=" + ordine,
                dataType: "html",
                success: function(risposta) {  
                    $("div#risposta").html(risposta);  
                    alert("ok!");
                },
                error: function(){
                    alert("Chiamata fallita!!!");
                } 
            }); 
            return false;  
        });
    });
</script>  

In my page (status.php) it works! But when I put a frame of status.php in index.php it doesn't work and change only the url like: ?cognome=Esposito&ordine=2121237391

What should I to in order to work as a frame in index.php ?

  • 写回答

1条回答 默认 最新

  • Memor.の 2015-09-16 09:48
    关注

    I used

      type: "GET",
      url: "http://stackoverflow.com/questions/32554239/ajax-post-without-refresh", 
    

    instead of your

       type: "POST",
      url: "http://****/new/action.php",  
    

    AND it works fine. (Just click on "Run snippet", it shows an error because the url doesn't support cross-domain)

    $(document).ready(function() {  
      $("form#iscrizione").submit(function(){   
        var ordine = $("#ordine").val();  
        var cognome = $("#cognome").val();
        $.ajax({  
          type: "GET",
          url: "http://stackoverflow.com/questions/32554239/ajax-post-without-refresh",  
          data: "cognome=" + cognome + "&ordine=" + ordine,
          dataType: "html",
          success: function(risposta) {  
            $("div#risposta").html(risposta);  
            alert("ok!");
          },
          error: function(){
                  alert("Chiamata fallita!!!");
    }
        }); 
        return false;  
      });
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <form id="iscrizione"> 
      
      <input type="text" value="get" id="cognome"><input type="text" value="get" id="ordine"><input type="submit" value="get"></form><div id="risposta"></div>

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题