

























1 function doAjax(url,msg,container){
2 // if the URL starts with http
3 if(url.match('^http')){
4 // assemble the YQL call
5 msg.removeClass('error');
6 msg.html(' (loading...)');
7 $.getJSON("http://query.yahooapis.com/v1/public/yql?"+
8 "q=select%20*%20from%20html%20where%20url%3D%22"+
9 encodeURIComponent(url)+
10 "%22&format=xml'&callback=?",
11 function(data){
12 if(data.results[0]){
13 var data = filterData(data.results[0]);
14 msg.html(' (ready.)');
15 container.
16 html(data).
17 focus().
18 effect("highlight",{},1000);
19 } else {
20 msg.html(' (error!)');
21 msg.addClass('error');
22 var errormsg = '<p>Error: could not load the page.</p>';
23 container.
24 html(errormsg).
25 focus().
26 effect('highlight',{color:'#c00'},1000);
27 }
28 }
29 );
30 } else {
31 $.ajax({
32 url: url,
33 timeout:5000,
34 success: function(data){
35 msg.html(' (ready.)');
36 container.
37 html(data).
38 focus().
39 effect("highlight",{},1000);
40 },
41 error: function(req,error){
42 msg.html(' (error!)');
43 msg.addClass('error');
44 if(error === 'error'){error = req.statusText;}
45 var errormsg = 'There was a communication error: '+error;
46 container.
47 html(errormsg).
48 focus().
49 effect('highlight',{color:'#c00'},1000);
50 },
51 beforeSend: function(data){
52 msg.removeClass('error');
53 msg.html(' (loading...)');
54 }
55 });
56 }
57 }
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。