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);
}
相关文档:
转载于http://xzio.javaeye.com/blog/91713
最初看到ajax感觉好惊喜啊,不用刷新全部页面,就可以更改局部页面数据。真的很方法
但是以为会很难,但实际做了才知道,AJAX很简单。至少入门很简单 如果你会ajax那就不要看了。更不要骂我。比我牛的人太多了
互相交流,学习。MSN:whw_dream(AT)hotmail.com
首先是jsp页面和 ......
test.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<html xmlns=
"http://www.w3.org/1999/xhtml"
>
<head>
<meta http-equiv=
"Content-Type"
conten ......
今天帮同事解决了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)
......
Ajax提交数据一般都是通过URL后边的参数形式来传递数据的,比如使用XMLHttpRequest.open('POST', url, true);的方式使用时,其url参数中就包含了需要提交的数据,它的形式如:http://www.mysite.com/handler.do?name='曹操'&sex='男',是把key=value形式的数据通过 &符号连接起来, ......