使用& lt; a>用ajax标记

Using <a> tag with ajax

本文关键字:ajax 标记 lt 使用      更新时间:2023-09-26

我有以下代码,它正在工作,但我想使用( <a> )标签而不是( <input type='submit'> )。我是php的初学者-我希望我的问题将被娱乐。我用谷歌搜索过我的问题,但是没有帮助。

<html>
<head>
    <script type="text/javascript">
        function load(thediv, thefile)
        {
            //alert('works');
            if(window.XMLHttpRequest)
            {
                xmlhttp = new  XMLHttpRequest();
            }
            else
            {
                xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
            }
            xmlhttp.onreadystatechange = function(){
            if(!(xmlhttp.readystate == 4 && xmlhttp.status == 200))
            {
                    // alert('works');
                    document.getElementById(thediv).innerHTML = xmlhttp.responseText;
            }
            }
            xmlhttp.open('GET', thefile, false );
            xmlhttp.send();
        }
    </script>
</head>
<body>
    <input type='submit' value="submit" onclick='load('main','itc_result.php');'>
</body>

你可以这样做:-

<a onclick="load('main','itc_result.php');">Click Me </a>.

但它需要什么还不清楚?

favorite
i have following code and its working but i want to use ( <a> ) tage instead of "( <input type='submit'> ) " i am a beginner in php, hope my question will be entertained, i have goggled my problem but it didn't help me
<html>
<head>
    <script type="text/javascript">
        function load(thediv, thefile)
        {
            //alert('works');
            if(window.XMLHttpRequest)
            {
                xmlhttp = new  XMLHttpRequest();
            }
            else
            {
                xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
            }
            xmlhttp.onreadystatechange = function(){
            if(!(xmlhttp.readystate == 4 && xmlhttp.status == 200))
            {
                    // alert('works');
                    document.getElementById(thediv).innerHTML = xmlhttp.responseText;
            }
            }
			alert('sending ajax');
            xmlhttp.open('GET', thefile, false );
            xmlhttp.send();
          
        }
    </script>
</head>
<body>
  <div id="main" />
    <a href="#" onclick="load('main','itc_result.php');" >submit</a>
</body>

将上述内容添加到锚标记的onclick中,像这样

<a href="#" onclick="load('main','itc_result.php');" >submit</a>