English 中文(简体)
1. 基本麻省逻辑
原标题:Basic ajax logic
  • 时间:2011-10-26 16:34:05
  •  标签:
  • php
  • html
  • ajax

在建议使用Ajax网页时,我决定尝试学习如何运作。 举例来说,我只是试图从一个营地档案中获取答复(这只是作为检验的一种简单描述),但它却不工作,因为实际上没有发生任何事情。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
   <title> Incident Center </title>
   <!--<link rel="stylesheet" href="http://web.njit.edu/~swp5/assignment/style/style.css">-->
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <script type="text/javascript">
    function onsubmit()
    {
        var sender;
        if (window.XMLHttpRequest)
        {
            sender=new XMLHttpRequest();
        }
        else
        {
            sender=new ActiveXObject("Microsoft.XMLHTTP");
        }
        sender.onreadystatechange=function()
        {
            if (sender.readyState==4 && sender.status==200)
            {
                document.getElementById("myDiv").innerHTML=sender.responseText;
            }
        }
        sender.open("GET","proz.php",true);
        sender.send();
    }
    </script>
</head>
<body>
    <div class="header">
        Incident Center 
    </div>

            <p>
                <button onclick="onsubmit()">Test</button>
            </p>


    <div id="myDiv"></div>
</body>
</html>
最佳回答

Using Opera 11.51 here, it doesn t actually like the fact that you use onsubmit() as a function name. Presumably because onsubmit() is actually already an eventhandler hook of a <button> element itself. I presume other browsers won t like this function name either.

因此,首先改称职能。 此处请上<条码>。

此外,请在<代码><form>要素中填写一个吨。 而由于一个违约的纽芬兰作为提交纽伦,提交表格,使网页重载。

为了防止这种情况,请将<代码>return不实; 并称之为onclick=“return dosubmit()”改为,或使丁顿成为button/code>的 but,如:<button category=“button” onclick=“dosubmit()”>

问题回答

正如我在评论中已经提到的那样,你应当检查你要求的答复守则,看看一看是否有错。 加入以下条目:<条码>广域修改>。 职能:

alert(sender.readyState +  ,   + sender.status +  ,   + sender.responseText);

根据这一产出,你可能确定你的错误。

http://www.jquery.com/“rel=“nofollow”http://www.jquery.com/

更方便地利用酒吧这样做,因为它在日本宇宙航空研究开发机构的职能中已经建成。 你的法典希望:

jQuery.ajax({
    type:  get ,
    url:  proz.php ,
        error: function(r) {
            alert("Something went wrong - "+r);
        }
    success: function(response) {
        alert(response);
    }
});

帮助的希望





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!