AppCan里面的Ajax通信实例

[code]
<!DOCTYPE html>
<html class="ui-mobile landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
<head>
<title>
</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link rel="stylesheet" href="css/ui-media.css">
<link rel="stylesheet" href="css/ui-base.css">
<link rel="stylesheet" href="css/ui-apple.css">
<script src="js/zy_anim.js">
</script>
<script src="js/jquery.js">
</script>
<script src="js/zy_control.js">
</script>
<script src="js/zy_tmpl.js">
</script>
<script>
zy_fix("header","footer",0,function()
{
/*请在此插入网页初始化代码*/
});
  function xmlHttp(){
    var url = document.getElementById(‘add’).value;
    uexXmlHttpMgr.open("1", "GET", url, ”);
    uexXmlHttpMgr.send("1");
}

  function httpSuccess(opid,result,data){
document.getElementById(‘adre’).innerHTML = "opCode:" + opid + "<br> result:" + result + "<br>data:" + data;
uexXmlHttpMgr.close("1");
}

  window.uexOnload = function(){
    uexXmlHttpMgr.onData = httpSuccess;
    uexWidgetOne.cbError = function(opCode, errorCode, errorInfo){
      alert("errorCode:" + errorCode + "nerrorInfo:" + errorInfo);
  }
}
</script>
</head>
<body class="ui-mobile-viewport" >

<!–header开始–>
<div id="header" data-role="header" class="ui-header ui-bar-c ui-header-fixed ui-bar-glass" >
<h1 class="ui-title" tabindex="0" role="heading" aria-level="1">
AppCan
</h1>
</div>
<!–header结束–>

<div id="page_0" class="ui-page ui-body-d ui-page-active" tabindex="0">
<!–content开始–>
<div class="tit">跨域异步请求接口</div>
    <div class="conbor">
    <div class="consj">
    <span>跨域异步请求接口测试:</span>
    <span>注:测试地址为蝌蚪项目首页信息地址,返回服务器的原始数据。</span>
    <span>请求内容:</span>
    <div class="tcxx" id="payy">
      <input class="textbox" type="text" id="add" value="http://www.kedo.gov.cn/mobile/index/GetIndexInfo.jsp?jsoncallback=?&type=1">
    </div>
    <input class="btn" type="button" value="取数据" onclick=xmlHttp()>
    <span>请求结果:</span>
    <div class="tcxx" id="adre"></div>
    <input class="btn" type="button" value="返回" onclick="uexWindow.back();">
    </div>
    </div>
</div>
<!–content结束–>

<!–footer开始–>
<div id="footer" data-role="footer" class="ui-footer ui-bar-a ui-footer-fixed">
<h1 class="ui-title ui-smaller" tabindex="0" role="footer" aria-level="1">
(c) Copyright 3G2WIN and others 2011.<br> All rights reserved.
</h1>
</div>
<!–footer结束–>

</body>

<script>
zy_init();
</script>
</html>
[/code]
主要是注意各个参数都是必填的。返回的data是主要数据。
在AppCan中不能用Jquery的Ajax主要是因为静态页是不能提交跨域请求的。浏览器会解析成file://这种格式,而不是http://

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇