Symbian WRT中使用JS自动将XML、JSON转换成为对象
2010-08-30 00:03:00 来源:WEB开发网function ajaxFetch(url, param, callback,exceptionCallBack, isXML) {
var req = new Ajax();
req.onreadystatechange = function() {
if (req.readyState == 4 && req.status == 200) {
if (!isXML && req.responseText != null) {
callback(req.responseText);
} else if (isXML && req.responseXML != null) {
callback(req.responseXML);
} else {
callback(null);
}
} else if (req.readyState == 4 && req.status != 200) {
if(exceptionCallBack!=null&&exceptionCallBack!=undefined)
exceptionCallBack();
}
}
var fullURL = url;
if (fullURL.indexOf("?") == -1) {
fullURL += "?";
} else {
fullURL += "&";
}
fullURL += "timestamp=" + (new Date().getTime());
fullURL += "&" + param;
req.open("GET", fullURL, true);
req.send(null);
}
ProcessData.js - 用于处理数据并且进行回调
Js代码
/**
* 构造方法
* @param {Object} Url xml JSON地址
* @param {Object} parentNode 父节点,比如要把
* @param {Object} options
* @param {Object} processDataFunction ???象弈?完成后需要整用的方法
*/
function ProcessData(Url, parentNode, options, processDataFunction){
this.URL = xmlUrl;
this.parentNode = parentNode;
this.options = options;
this.processDataFunction = processDataFunction;
selfProcessData = this;
}
ProcessData.prototype = new Object();
ProcessData.prototype.URL;
ProcessData.prototype.options;
ProcessData.prototype.parentNode;
ProcessData.prototype.processDataFunction;
ProcessData.prototype.dataArray;
更多精彩
赞助商链接