xmlHttp.responseText不能从json webservice返回数据
xmlHttp.responseText does not return data from json webservice
我试图从json webservice检索数据。
if (xmlHttp.status == 200 || xmlHttp.status == 0)
{
var result = xmlHttp.responseText;
json = eval("(" + result + ")");
}
我没有得到var结果。当我用包含json对象的文本文件替换webservice时,我可以检索json对象作为responseText。请帮助
重要的事情先说…永远,永远,永远不要使用eval
*。eval
= evil.
如何使用GET
与AJAX…
try {
http = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e1) {
try {
http = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
this.xmlhttp = null;
}
}
var url = "/uri/of/web-service?val1=Laura&val2=Linney" + Math.random();
var params = "val1=Laura&val2=Linney";
http.open("GET", url, true);
http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) {
// we have a response and this is where we do something with it
json = JSON.parse(http.responseText);
}
}
http.send();
如何使用POST
与AJAX…
try {
http = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e1) {
try {
http = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
this.xmlhttp = null;
}
}
var url = "/uri/of/web-service";
var params = "val1=Laura&val2=Linney";
http.open("POST", url, true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) {
// we have a response and this is where we do something with it
json = JSON.parse(http.responseText);
}
}
http.send(params);
相关文章:
- 节点导出返回一个空对象
- ES6构造函数返回基类的实例
- 监视函数从服务返回不起作用,但作用域函数起作用
- 控制台返回var不是't定义,但它是
- 从函数返回角度承诺
- Javascript返回值只在循环中返回一次
- 从控制器返回后Ajax启动事件激发
- CKFinder 3为所选文件返回错误的URL
- 如何在d3.js中返回路径的y坐标
- 如何从jquery函数返回变量
- 如何对webservice返回的xml进行排序
- Javascript值从webservice返回,但不会显示,除非使用了断点
- 修改从WebService返回的文本
- asp.net→javascript→网络服务→从webservice调用返回两个类
- 简单的javascript wcf webservice调用成功时返回null
- 从javascript调用Java restful webservice时返回值失败
- 从webservice返回文件路径,并在新窗口中打开它
- 启用Ajax的webservice返回一个列表,JS是如何理解列表的
- 在asp.net webservice中返回json
- xmlHttp.responseText不能从json webservice返回数据