发新话题
打印

[AJAX应用] Ajax Hacks-Hack 5.取得普通字符串

Ajax Hacks-Hack 5.取得普通字符串

Ajax Hacks-Hack 5.取得普通字符串

管理天气信息,股票高价,以及其他不使用XML的时候,就是用到了普通字符串。

request 对象有时候不使用XML: request.responseText也可以很好的应用于web应用。本hack讲述用户通过选择一个股票代号,然后从服务器以字符串的格式取得该股票的价格。在下一个hack中取得股票的价格是以数字的格式。


首先看一下页面的HTML代码,其中引入了源文件hack9.js



http://www.w3.org/TR/1999/REC-html401–19991224/strict.dtd”>



Stock prices
javascript:void%200>
“getStockPrice(this.stSymbol.value);return false”>


Enter stock symbol:  
“stSymbol“ size=“4”>




Get Stock Price



图1-5是页面在firefox中的显示。用户输入股票代号如“GRMN”,然后点击取得股票价格按钮;程序向服务器发送股票代号信息,然后以字符串的格式从服务器取得相应的价格,并显示出来。


函数getStockPrice是请求处理函数。函数从页面取得股票代号,并取得从服务器返回的股票价格(是用请求对象同服务器组建通信,取得实时的股票价格)。代码如下:


var request;

var symbol; //保存股票代号

function getStockPrice(sym){

symbol=sym;

if(sym){

var url=“http://www.parkerriver.com/s/stocks?symbol=”+sym;

httpRequest(“GET”,url,true);

}

}


//XMLHttpRequest 事件处理函数

function handleResponse( ){

if(request.readyState == 4){

if(request.status == 200){

/* Grab the result as a string */

var stockPrice = request.responseText;

var info = “«The price is: $“+stockPrice+“»”;

document.getElementById(“stPrice“.style.fontSize=“0.9em”;

document.getElementById(“stPrice”.style.

backgroundColor=“yellow”;

document.getElementById(“stPrice”.innerHTML=info;


} else {

alert(“A problem occurred with communicating between ”+

“the XMLHttpRequest object and the server program.”;

}

}//end outer if

}


/* 在Hack #1 察看httpRequest( ) 函数的代码;在这里省略 */

函数getStockPrice里边调用了函数httpRequest,该函数负责设置request对象。如果读者已经看了本章的前几个hacks,就会明白handleResponse封装了更重要的动作。


function handleResponse(){

if(request.readyState == 4){

if(request.status == 200){

/*Grab the result as a string*/

var stockPrice = request.responseText;

var info = “«The price is: $“+stockPrice+“»”;

document.getElementById(“stPrice“.style.fontSize=“0.9em”;

document.getElementById(“stPrice“.style.backgroundColor=“yellow”;

document.getElementById(“stPrice”.innerHTML =info;


} else {

alert(“A problem occurred with communicating between the XMLHttpRequest object and the server program.”;

}

}//end outer if

}


当请求完成后(即:request.readyState 的值为4),HTTP响应状态为400(表示请求成功),代码使用request.responseText来取得服务器的响应。代码然后是用DOM来显示相关信息。


document.getElementById("stPrice").style.fontSize="0.9em";

document.getElementById(“stPrice“.style.backgroundColor=“yellow”;

document.getElementById(“stPrice”.innerHTML =info;


本hack讲的是如何通过request.responseText来取得服务器的响应信息,取得何种格式的信息要取决于服务器响应的信息的格式。
这世界总有你不明白

TOP

反击破 锤式反击破碎机

机制砂生产线、碎石设备生产线、机制砂生产线、碎石机、破碎机、第三代制沙机

TOP

石料生产线

郑州环球重工机械有限公司专业生产碎石生产线,选矿生产线,制砂生产线
联系方式:
地 址:郑州市南阳路216号
电 话:86-371-67878896

TOP

呵呵,给老大顶起来!

沈阳宏海机械厂www.086hh.com批发零售双锅爆米花机,豪华机身面板,金属齿轮电机,交直流两用,可移动作业,燃气加热电搅拌系列!特殊供应商场专用全电动双锅爆米花机!同时供应具有同等性能的单锅爆米花机!另外还有特制双层锅底的不锈钢手摇爆米花锅、电瓶爆米花锅,以满足用户的不同需求!常年提供爆米花专用美国小玉米99%爆花率,省级检测的爆米花专用果味奶油,可生产出10余种不同口味的爆米花,味道特别香浓!每锅成本不超过1元钱,根据当地情况可卖4-5元钱!是您致富的好帮手!电话:024-82116562 QQ:491783951
沈阳宏海

TOP

TOP

传奇世界私服 王者风范传奇世界私服

很多人都喜欢传奇世界私服这个游戏
我也很喜欢,但是大家都觉得这个游戏不稳定
王者风范
传奇世界私服是现在比较盛行的传奇世界私服中最稳定的,最好玩的传奇世界私服
王者风范
传奇世界私服游戏在线人数很多的,高手也很多。
很多喜欢传奇世界私服的朋友都喜欢到王者风范
传奇世界私服
大家选择王者风范传奇世界私服,一定会觉得我没有推荐错的。
专业从事网站优化,SEO,搜索引擎优化等专业网络技术

TOP

2moons dofus GW aoc who new 1

NEW DELHI -- A series of bombs exploded across the ancient city of Jaipur, killing at least 60 people and transforming busy markets,2moons dil a jewelry bazaar and a Hindu temple into scenes of carnage.

All seven blasts Tuesday were within the old walls of the western city known for its pink-hued palaces, and suspicion quickly fell on Islamic militant groups blamed for a string of attacks in India in recent years. Police said an eighth bomb was found and defused by police.guild wars gold

"Obviously, it's a terrorist" attack, said A.S. Gill, the police chief of Rajasthan, the state where Jaipur is located. "The way it has been done, the attempt was to cause the maximum damage to human life."

The explosions began around 7:30 pm. One went off at a dofus kamas market near a temple dedicated to the Hindu monkey god Hanuman. Tuesday is the day of worship set aside for Hanuman, and the temple was crowded with people offering prayers on the way home from work.

Another bomb detonated near the Johari Bazaar, the city's jewelry market that is a popular destination for tourists. The tourist season ended in March, however, and there were no immediate indication that foreigners had been caught in any of the explosions.

Parikshit Bhandari, who saw the attack near the jewelry market, said there was "blood all around and wounded people crawling on the ground."

Bombing sites were littered with dropped shopping bags, mangled bicycles, damaged cars and overturned bicycle rickshaws, the most popular mode of transport in the crowded lanes of Jaipur.

A senior Rajasthan police officer, A.K. Jain, said 60 people were killed and 150 wounded.

No one claimed responsibility for the attack, as is the case with most bombings in India. But within hours of the blasts, authorities were suggesting that blame would eventually fall on Pakistan and the Islamic militant groups that India accuses its neighbor of backing.

"One can't rule out the involvement of a foreign power," said India's junior home minister, Sriprakash Jaiswal, using language commonly understood to refer to Pakistan.

Jaiswal refused to say if he was talking about Pakistan. But he suggested the bombings were connected to previous attacks on India, saying that "the blasts are part of a big conspiracy."

Indian authorities have blamed Pakistan-based Islamic extremist groups for a spate of bombings that have killed nearly 400 people in this predominantly Hindu country of 1.1 billion people since 2005. Pakistan, an overwhelmingly Muslim country, denies any role in the bombings.

The attacks have run the gamut from July 2006 train bombings that killed nearly 200 people in Mumbai, India's financial center, to small blasts like the one that struck a Muslim shrine in Rajasthan last year, killing two people.

Each new bombing has brought fears of a fresh outbreak of the violence between Hindus and Muslims that has sporadically bled India throughout its history, warhammer onling gold and authorities appealed for calm after Tuesday's attack.

Authorities quickly ordered alerts in New Delhi, Mumbai and several other cities. Security was also stepped up at airports and railway stations across the country.

In Washington, the US government condemned the attack.

Jaipur is one of the major attractions in Rajasthan, a desert region dotted with palaces and temples that draw hundreds of thousands of Indians and foreigners every year, from bargain-hunting backpackers to celebrities like Mick Jagger.


Associated Press reporters Sam Dolnick, Muneeza Naqvi and Ashok Sharma contributed to this report.
age of Conan gold

TOP

麻辣烫炉,烤玉米机,面条机,巧克力喷泉机,炒冰机

致富机械,致富好助手,沈阳基石东方机械有限公司提供 www.js888.net

麻辣烫炉          www.js888.net
烤玉米机          www.js888.net
面条机             www.js888.net
巧克力喷泉机    www.js888.net
炒冰机             www.js888.net

TOP

代写论文K

新手报道请大家多多包含!!呵呵   希望;论坛越办越好!!!!!




















代写论文 硕士论文 职称论文 我们代写论文保证原创,以优质的服务助您论文代写,专业提供论文代写服务-专业成就未来,诚信服务大家!...

TOP

铁板烧,冷面机,肉丸机,梅花糕,豆浆机www.81821960.com

致富机械,致富好助手,沈阳基石东方机械有限公司提供 www.81821960.com

铁板烧       www.81821960.com
冷面机       www.81821960.com
肉丸机       www.81821960.com
梅花糕       www.81821960.com
豆浆机       www.81821960.com

TOP

机票

不错不错,支持!!呵呵

   












中国特价机票网是打折机票行业的机票普及、机票采购、机票技术、特价机票会展、机票招标行业平台是中国最大的机票权威网站,并以及时的机票新闻、海量的机票资讯和独到的机票信息分析,为广大机票爱好者机票订制服务是最权威的机票专场会议,机票专家为您精选的机票产品,迎您来展示您的打折机票产品机票发布服务基于特价机票经验丰富的机票企划人员和准确的机票投放系统特价机票可以为机票客户顾名思义就是忠诚与机票的用户,是集机票客户,网络机票媒体,致力与特价机票厂家为一体机票知识应用及机票产品的价值升华。

TOP

发新话题