一个ajax的有关问题

WBOY
发布: 2016-06-13 13:39:13
原创
768 人浏览过

一个ajax的问题
ajax.php

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->


<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script>
    function GetXmlHttpObject()
    {
        var XMLHttp=null;
        try
        {
            XMLHttp=new XMLHttpRequest();
        }
        catch(e)
        {
            try
            {
                XMLHttp=new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e)
            {
                XMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
        }
        return XMLHttp;
    }
    
    
    function submit_form(tag)
    {
        XMLHttp=GetXmlHttpObject();
        var aurl="deal_ajax.php?tag="+tag+"&url="+document.getElementById("url").value+"";
        XMLHttp.open("GET",aurl,true);
        XMLHttp.send(null);
        XMLHttp.onreadystatechange=function()
        {
            if(XMLHttp.readyState==4&&XMLHttp.status==200)
            {
                document.getElementById("status").innerHTML=XMLHttp.responseText;
            }
        }
    }
</script>



<div align="center" style="text-align:center">
<form action="" method="post">
<table width="900" border="1">
  <tr>
    <td>url</td>
    <td><input name="url" type="text" style="width:400px" id="url"></td>
  </tr>
  <tr>
    <td>message</td>
    <td><textarea name="message" cols="" rows="" id="message"></textarea></td>
  </tr>
  <tr>
    <td><input name="save" type="submit" value="保存" id="save" onclick="submit_form('later')"></td>
    <td><input name="fabu" type="submit" value="发布" id="fabu" onclick=""></td>
  </tr>
</table>

</form>
<div id="status"></div>
</div>


登录后复制


deal_ajax.php
PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php echo "#######@".$_REQUEST['url'];
?>

登录后复制


点击“保存”按钮可以异步提交到deal_ajax.php,但是马上就走form的action了!!!!用post也是

------解决方案--------------------


------解决方案--------------------
type="submit" 

改成
type="button"
------解决方案--------------------
onclick="submit_form('later');return false"
------解决方案--------------------
PHP code

echo "<meta http-equiv="Content-Type" content="text/html; charset=utf-8">" .
        "<script type="text/javascript" language="javascript">".
        "if(confirm('ok')){" .
        "    window.location.href='{$href}';" .
        "} else{
            history.back();
        }" .
        "</script>";
        exit; <div class="clear">
                 
              
              
        
            </div>
登录后复制
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!