IDE 缺少基础能力集调用库,这是一个简单的Ajax调用。
var jsonObj;
var xmlhttp = null;
function callAsync(url, callbackSuccess)
{
xmlhttp = new Ajax();
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange=function()
{
// readyState = 4 ; "complete"
if (xmlhttp.readyState==4)
{
// status = 200 ; "ok"
if(xmlhttp.status == 200)
{
uiManager.showNotification(1000, "ok", "Done");
/*
* Remove the substr "jsonFlickrApi(" from the responseText
*/
var text = xmlhttp.responseText;
text = text.substr(14, text.length-15);
// Create JSON Oject
jsonObj = eval('(' + text + ')');
callbackSuccess(jsonObj);
}
else
{
uiManager.showNotification(1000, "warning", "Failed to get data from server");
}
}
}
xmlhttp.send(null);
}
相关文档:
<scrīpt Language="Javascrīpt">
<!--
// author:奔腾的心
// qq:7180001
function Ajax(OnError,OnState,OnDownloadEnd)
{
this.ErrorStr = null;
......
前段时间写JSP,使用AJAX以POST方式提交数据,如果是中文字符提交就会乱码,后来写ASP时用到AJAX以POST方式提交数据,中文一样是乱码。搜索一下相关资料,问题应该是提交数据时是以UTF-8编码提交,所以接收时如果使用GB2312或者其它中文编码的话就会乱码。
使用GET方式提交数据的时候,中文问题很好解决,setRequestHeader ......
今天帮同事解决了js异步调用时出现了中文乱码的问题,具体解决办法如下:
1)首先确认js是否没有对后台传输过来的中文进行解码。
按照网络上写的方法通过js对response的读取出来数据进行多次测试,发现仍然不能解决,细想不一定是此处问题。改换其他办法解决。
2)如果解码解决不了,再看是否是因为网 ......
function sendAsynchronRequest(url,parameter,callback){
createXMLHttpRequest();
if(parameter == null){
xmlHttp.onreadystatechange = callback;
xmlHttp.open("GET",url,true);//当GET请求时,在地址栏中是带参数的,而参数为NULL,所以用get请求,send(null)
......