<script>var apiname;
function handleStateChange()
{
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
result = xmlHttp.responseText;
//alert("The server replied with:" + result);
apiname=(result.substring(result.indexOf("<title>")+7,result.indexOf("</title>")));
alert(apiname);
}
else{
//alert(xmlHttp.status);
}
}
else{
window.status = xmlHttp.readyState;
}
}
function startRequest(s)
{
if (window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET",s, true);
xmlHttp.send(null);
//return ??
//怎样返回handleStateChange() alert的内容?
}
var a;
a = startRequest("http://www.baidu.com");
</script>请问怎样返回handleStateChange() 里面 alert的内容?想把网页源码赋值给变量a,不会写
如果在handleStateChange()里面return apiname,startRequest()得到的是undefined,
function handleStateChange()
{
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
result = xmlHttp.responseText;
//alert("The server replied with:" + result);
apiname=(result.substring(result.indexOf("<title>")+7,result.indexOf("</title>")));
alert(apiname);
}
else{
//alert(xmlHttp.status);
}
}
else{
window.status = xmlHttp.readyState;
}
}
function startRequest(s)
{
if (window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET",s, true);
xmlHttp.send(null);
//return ??
//怎样返回handleStateChange() alert的内容?
}
var a;
a = startRequest("http://www.baidu.com");
</script>请问怎样返回handleStateChange() 里面 alert的内容?想把网页源码赋值给变量a,不会写
如果在handleStateChange()里面return apiname,startRequest()得到的是undefined,
解决方案 »
- JS正则表达式进行三个IF判断,最后一个不生效
- 如何能让我的页面所有的javascript调用完了,再显示页面啊?
- 如何让页面一个适应不同分辩率 !求救,急啊!!!!!!!!!!!!!!
- 如何在JavaScript中调用Session? 急
- 能用javascript写代码实现插入数据到数据库的功能吗,怎么实现?在线等
- 关于<table>折行
- 着急回家呢,帮忙解决个问题!
- JavaScript 有没有办法自己发Email?
- document.execCommand('Italic') 不同浏览器居然插入不同标签,怎么办?
- ExtJS里自定义对象,extent: 'Ext.form.Panel', 调用render()无效
- 请教一个js设置ie6和ie8浏览器的文字大小的问题。(解决立刻给分)
- 怎样用JS读取<iframe></iframe>里面的值呢?
xmlHttp.open("GET",s, true);
把这个改为:
xmlHttp.open("GET",s, false);
这样,可以得到值。
xmlHttp.open("GET",s, true);
把这个改为:
xmlHttp.open("GET",s, false);
这样,可以得到值。
<script>var apiname;
function handleStateChange()
{
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
result = xmlHttp.responseText;
//alert("The server replied with:" + result);
apiname=(result.substring(result.indexOf("<title>")+7,result.indexOf("</title>")));
//alert(apiname);
}
else{
//alert(xmlHttp.status);
}
}
else{
window.status = xmlHttp.readyState;
}
}
function startRequest(s)
{
if (window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET",s, false);
xmlHttp.send(null);
//return ??
//怎样返回handleStateChange() alert的内容?
}
var a;
a = startRequest("http://www.baidu.com");
alert(a);
</script>改成false了,可alert(a);还是undefined
等到服务器返回数据赋给apiname的时候你就可以直接赋给变量a
其实这个时候你已经抓取了返回数据,不用再定义一个a来保存结果了。
function handleStateChange()
{
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
result = xmlHttp.responseText;
//alert("The server replied with:" + result);
apiname=(result.substring(result.indexOf("<title>")+7,result.indexOf("</title>")));
alert(apiname);
}
else{
//alert(xmlHttp.status);
}
}
else{
window.status = xmlHttp.readyState;
}
}
var xmlHttp;//全局变量
function startRequest(s)
{
if (window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
xmlHttp.open("GET",s, true);//这里的true/false是异步、同步设置
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.send(null);
//return ??
//怎样返回handleStateChange() alert的内容?
}
var a;
a = startRequest("http://www.baidu.com");
</script>
var xmlHttp;//全局变量
function startRequest(s)
{
if (window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
xmlHttp.open("GET",s, true);//这里的true/false是异步、同步设置
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.send(null);
//return ??
//怎样返回handleStateChange() alert的内容?
}//换个位置,不然xmlHttp可能会是undefined
function handleStateChange()
{
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
result = xmlHttp.responseText;
//alert("The server replied with:" + result);
apiname=(result.substring(result.indexOf("<title>")+7,result.indexOf("</title>")));
alert(apiname);
}
else{
//alert(xmlHttp.status);
}
}
else{
window.status = xmlHttp.readyState;
}
}var a;
a = startRequest("http://www.baidu.com");
</script>