longlong
longlong
  • 发布:2014-12-23 17:49
  • 更新:2016-07-09 10:30
  • 阅读:4100

mui的ajax具怎么用?能像jquery那样用吗?像下面我这样的问题怎么解决?

分类:MUI

我在后端写了接口调用数据,php写的如下:

    public function mlist(){  
        $sql = "select id,title,author,dateline,lastupdate,picture,keywords,price from items order by id desc limit 10";  
        $this->db->query($sql);  
        $ret = $this->db->fetch_array();  
        echo json_encode($ret);  
    }

然后我在mui模板内写前端调用这个接口数据:


    (function($) {  
        var methodEl = 'get';  
        var dataTypeEl = 'html';  
        var respnoseEl = document.getElementById("list-li");  
        //成功响应的回调函数  
        var success = function(response) {  
            //response = JSON.stringify(response);  
            //console.log(response);   
            //respnoseEl.innerHTML = response;  
            for(var i in response){  
                console.log(response[i].title);  
            }  
        };  
        var ajax = function() {  
            //利用RunJS的Echo Ajax功能测试  
            var url = 'http://www.miledou.com/index.php?m=content&c=mui&a=mlist';  
            //请求方式,默认为Get;  
            var type = methodEl;  
            //预期服务器范围的数据类型  
            var dataType = dataTypeEl;  
            respnoseEl.innerHTML = '正在请求中...';  
            $.get(url,success);   
        };  

        ajax();   

        mui.plusReady(function(){  
            //关闭等待框  
            plus.nativeUI.closeWaiting();  
            //显示当前页面  
            mui.currentWebview.show();  
          });  

    })(mui);  

拿不到循环出来的数据,整体log出来是这样的:

<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><title>[1/2] </title><script type="text/javascript">function _conoff(id){var d=document.getElementById(id);var a=document.getElementById(id+"_a");if(d&&a){d.style.display=d.style.display=="none"?"block":"none";a.innerHTML=d.style.display=="none"?a.innerHTML.replace(/\-/g,"+"):a.innerHTML.replace(/\+/g,"-");}}</script><style type="text/css">body{font-size:15px;margin:3px;padding:0px;line-height:150%;} img{border:0px;} form{margin-top:0px;margin-bottom:0px;} table{font-size:15px;border:0px;} input{font-size:15px;} hr{color:#666666;} small{font-size:100%;} big{font-size:110%;}</style></head><body>[{&quot;id&quot;:&quot;1187&quot;,&quot;title&quot;:&quot;\u5973\u58eb\u51ac\u88c5\u52a0\u539a\u7fbd\u7ed2\u4e2d\u957f\u6b3e2014\u65b0\u6b3e\u4fee\u8eab\u5973\u7fbd\u7ed2\u8fde\u5e3d\u5916\u5957\u827e\u5a03\u4f9d\u59ae&quot;,&quot;author&quot;:&quot;35425506917&quot;,&quot;dateline&quot;:&quot;1418664972&quot;,&quot;lastupdate&quot;:&quot;1418664972&quot;,&quot;picture&quot;:&quot;\/go\/img.php?uuu=i1\/T1JDdyFA8cXXXXXXXX_!!0-item_pic.jpg_220x220.jpg&quot;,&quot;keywords&quot;:&quot;\u7fbd\u7ed2\u5973&quot;,&quot;price&quot;:&quot;599.00&quot;},{&quot;id&quot;:&quot;1186&quot;,&quot;title&quot;:&quot;\u5962\u534e\u4fee\u8eab\u663e\u7626\u7fbd\u7ed2\u68c9\u670d\u5973\u8d85\u957f\u6b3e\u8fc7\u819d\u52a0\u539a\u5927\u6bdb\u9886\u8fde\u5e3d2014\u65b0\u6b3e\u6f6e\u97e9\u7248&quot;,&quot;author&quot;:&quot;42590597641&quot;,&quot;dateline&quot;:&quot;1418664969&quot;,&quot;lastupdate&quot;:&quot;1418664969&quot;,&quot;picture&quot;:&quot;\/go\/img.php?uuu=i2\/TB1CaiFGFXXXXXmaXXXXXXXXXXX_!!0-item_pic.jpg_220x220.jpg&quot;,&quot;keywords&quot;:&quot;\u7fbd\u7ed2\u5973&quot;,&quot;price&quot;:&quot;266.00&quot;},{&quot;id&quot;:&quot;1185&quot;,&quot;title&quot;:&quot;\u6f6e2014\u51ac\u7fbd\u7ed2\u68c9\u670d\u5973\u4e2d\u957f\u6b3e\u52a0\u539a\u5b66\u751f\u51ac\u88c5\u5916\u5957\u68c9\u8863\u5973\u68c9\u8884\u5973\u97e9\u7248&quot;,&quot;author&quot;:&quot;42404075522&quot;,&quot;dateline&quot;:&quot;1418664968&quot;,&quot;lastupdate&quot;:&quot;1418664968&quot;,&quot;picture&quot;:&quot;\/go\/img.php?uuu=i1\/TB1eiwgGFXXXXcSXVXXXXXXXXXX_!!0-item_pic.jpg_220x220.jpg&quot;,&quot;keywords&quot;:&quot;\u7fbd\u7ed2\u5973&quot;,&quot;price&quot;:&quot;178.00&quot;},{&quot;id&quot;:&quot;1184&quot;,&quot;title&quot;:&quot;\u97e9\u7248\u5916\u5957\u4f11\u95f2\u77ed\u6b3e\u65f6\u5c1a\u62fc\u8272\u52a0\u539a\u8fde\u5e3d\u519b\u5de5\u88c5\u65b0\u6b3e\u7fbd\u7ed2\u68c9\u670d\u59732014\u51ac\u88c5&quot;,&quot;author&quot;:&quot;41509160047&quot;,&quot;dateline&quot;:&quot;1418664966&quot;,&quot;lastupdate&quot;:&quot;1418664966&quot;,&quot;picture&quot;:&quot;\/go\/img.php?uuu=i2\/TB1c0D0GVXXXXXdXXXXXXXXXXXX_!!0-item_pic.jpg_220x220.jpg&quot;,&quot;keywords&quot;:&quot;\u7fbd\u7ed2\u5973&quot;,&quot;price&quot;:&quot;188.00&quot;},{&quot;id&quot;:&quot;1183&quot;,&quot;title&quot;:&quot;\u65b0\u6b3e\u4fee\u8eab\u957f\u6b3e\u97e9\u7248\u7fbd\u7ed2\u670d\u5973\u52a0\u539a\u4fdd\u6696\u8fde\u5e3d\u7fbd\u7ed2\u68c9\u670d\u5916\u5957shezgood&quot;,&quot;author&quot;:&quot;42660666697&quot;,&quot;dateline&quot;:&quot;1418664963&quot;,&quot;lastupdate&quot;:&quot;1418664963&quot;,&quot;picture&quot;:&quot;\/go\/img.php?uuu=i3\/TB13q1hGVXXXXakXFXXXXXXXXXX_!!0-item_pic.jpg_220x220.jpg&quot;,&quot;keywords&quot;:&quot;\u7fbd\u7ed2\u5973&quot;,&quot;price&quot;:&quot;369.00&quot;},{&quot;id&quot;:&quot;1182&quot;,&quot;title&quot;:&quot;\u8f7b\u8584\u6b3e\u5973\u88c5\u4f18\u8863\u5e93\u7fbd\u7ed2\u670d\u5973\u8fde\u5e3d\u4fee\u8eab\u5927\u7801\u51ac\u88c5\u80d6\u59b9\u59b9\u8f7b\u7fbd\u7ed22014\u65b0\u6b3e&quot;,&quot;author&quot;:&quot;41830356094&quot;,&quot;dateline&quot;:&quot;1418664961&quot;,&quot;lastupdate&quot;:&quot;1418664961&quot;,&quot;picture&quot;:&quot;\/go\/img.php?uuu=i2\/TB1hVLTGFXXXXXgX  

解决怎么处理数据?ajax具体用法是怎么样的?如果像jquery那样用我会用,现在卡到这了555555555

2014-12-23 17:49 负责人:无 分享
已邀请:
DCloud_UNI_FXY

DCloud_UNI_FXY

mui.getJSON调用。

服务端返回时指定正确的content-type

longlong

longlong (作者) - 自信可爱!

谢谢了,根据大牛的指导在自己服务端加了一句这个:
header("Content-type:application/json; charset=utf-8");

搞定了!

packychu2008@qq.com

packychu2008@qq.com

我用MUI.AJAX來回傳PHP數據, 但出現錯誤, "this site requires javascript to work",其實我想直接把數據傳回網頁,要如何呢!!請指教...

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title></title>
<script src="js/mui.min.js"></script>
<link href="css/mui.min.css" rel="stylesheet"/>
<script type="text/javascript" charset="utf-8">
mui.init();
</script>

</head>
<body>

<script>
function showHint(str) {
if (str.length == 0) {
document.getElementById("txtHint").innerHTML = "";
return;
} else {

  var url = 'http://hktc.erufa.com/show.php'  
  mui.ajax(url,{  

 data:{  
    'q':str  
},  

dataType:'html'  
type:'get'  
timeout:30000,  

success:function(data){  

    //服务器返回响应,根据响应结果,分析是否登录成功;  
     alert(data);  

},  

error:function(xhr,type,errorThrown){  

    //异常处理;  
    console.log(type);  
}  

});

}  

}
</script>
</head>
<body>

<p><b>Start typing a name in the input field below:</b></p>
<form>
First name: <input type="text" onkeyup="showHint(this.value)">
</form>
<p>Suggestions: <span id="txtHint"></span></p>
</body>
</html>

ljn936@wo.com

ljn936@wo.com

为什么 mui ajax都会调用两次?

该问题目前已经被锁定, 无法添加新回复