首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ajax send()函数的问题

ajax send()函数的问题
EN

Stack Overflow用户
提问于 2013-05-30 17:29:21
回答 1查看 75关注 0票数 0
代码语言:javascript
运行
复制
<!DOCTYPE html>
<html>
<head>
<title>Lesson 18: Making AJAX Calls</title>
</head>
<body>
<h1>Lesson 18: Making AJAX Calls - Plain Text Response</h1>
<div>
<h2 id="myHeader">Click the button to call your data</h2>
<input type="button" value="Click Me!" onclick="getText('test.txt')" />
</div>
<script type="text/javascript">
var myRequest;
function getText(url)
        {        
            if (window.XMLHttpRequest)        
            {        
            myRequest = new XMLHttpRequest();        
            }        
            else        
            {        
            myRequest = new ActiveXObject("Microsoft.XMLHTTP");        
            }
        myRequest.open("GET", url, true);
        myRequest.send(null);    
        myRequest.onreadystatechange = getData;        
        }
function getData()        
        {
        var myHeader = document.getElementById("myHeader");
        if (myRequest.readyState ===4)        
            {        
        if (myRequest.status === 200)    
            {
        var text = myRequest.responseText;
        myHeader.firstChild.nodeValue = text;        
            }        
        }        
        }        
        </script>            
        </body>
        </html>

这段代码来自本教程:http://www.html.net/tutorials/javascript/lesson18.php

问题:

这是什么意思: myRequest.send(null);它和myRequest.send();有什么区别?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-30 17:41:34

没什么区别。.send(null)表示您在请求正文中发送的内容为空。.send()表示在请求体中不发送任何内容。在GET请求的情况下没有区别,因为没有发送请求正文。在POST请求的情况下,也没有区别。

看看这个:Why do we pass null to XMLHttpRequest.send?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16832488

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档