We are quite new with JQuery mobile development targetting for Cordova/PhoneGap. However, we've managed to get working few pages relating displaying CATEGORY list, SUBCATEGORY list, ADS list, AD detail using JSONP and listview.
We are currently stuck in SEARCH page. When we do the console.log(JSON.stringify(row)); it returns the data per line so that proves that the JSON query is successfully working like the rest of the pages above BUT won't refreshed listview for some reason for this SEARCH page ?!?!
Are we using the right page event here ?
Thanks for the input.
<!DOCTYPE html>
<html>
<head>
<title>Search Ads</title>
<meta name="viewport" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.3/jquery.mobile-1.4.3.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.3/jquery.mobile-1.4.3.min.js"></script>
<script type="text/javascript">
function getQueryStrings()
{
var assoc = {};
var decode = function (s) { return decodeURIComponent(s.replace(/\+/g, " ")); };
var queryString = location.search.substring(1);
var keyValues = queryString.split('&');
for(var i in keyValues)
{
var key = keyValues[i].split('=');
if (key.length > 1) {
assoc[decode(key[0])] = decode(key[1]);
}
}
return assoc;
}
$(document).ready(function()
{
$("#submitid").click(function() {
var textsearch = $('#txtsearch').val();
//var qs = getQueryStrings();
//var catid = qs["catid"];
//var subcatid = qs["subcatid"];
//var page = qs["page"];
//var reclimit = qs["reclimit"];
var catid = null;
var subcatid = null;
var page;
if (page == null)
page = 1;
var reclimit;
if (reclimit == null)
reclimit = 30;
console.log("textsearch: " + textsearch);
console.log("catid: " + catid);
console.log("subcatid: " + subcatid);
console.log("page: " + page);
console.log("reclimit: " + reclimit);
var url = 'http://www.dewalist.com/webservices/',
mode = 'server.php?',
queryName = '&query=SearchAds',
parameters = 'searchstring=' + textsearch + '&catid=' + catid + '&subcatid=' + subcatid + '&page=' + page + '&reclimit=' + reclimit ,
callback = '&callback=SearchAds',
key = 'api_key=470fd2ec8853e25d2f8d86f685d2270e';
console.log("URL: " + url + mode + parameters + queryName + callback);
$.ajax({
type: 'GET',
url: url + mode + parameters + queryName + callback,
dataType: "jsonp",
jsonpCallback: "SearchAds",
contentType: 'application/json; charset=utf-8',
success: function (result)
{
console.log(result);
$.each(result, function(i, row) {
console.log(JSON.stringify(row));
$('#ad-list').append('<li><a data-ajax="false" href="ad.html?adid=' + row.adid + '" data-id="' + row.subcatid + '"><h3>' + row.adtitle + '</h3></a><h1>' + row.addesc + '</h1></li>');
});
$('#ad-list').listview('refresh');
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(url + mode + parameters + queryName + callback),
console.log(errorThrown);
console.log(textStatus);
}
});
});
});
</script>
</head>
<body>
<div data-role="page" id="searchads">
<div data-theme="a" data-role="header" data-position="fixed">
<a href="#" class="ui-btn-left" data-rel="back" data-transition="slide" id="back-to-ads">Back</a>
<h3>Ads</h3>
<div data-role="navbar">
<ul>
<li><a href="home.html" data-ajax="false" data-icon="home" data-iconpos="notext" data-role="button">Home</a></li>
<li><a href="post.html" data-ajax="false" data-icon="plus">Post Ad</a></li>
<li><a href="#" data-icon="navigation" data-iconpos="notext" data-role="button">Change City</a></li>
<li><a href="post.html" data-ajax="false" data-icon="search">Search</a></li>
</ul>
</div>
</div>
<div data-role="content" data-theme="a" data-fullscreen="true">
<form id="sitepreference">
<input id="txtsearch" type="search" name="search" value="" />
<button id="submitid" name="submit" type="submit">Search</search>
</form>
<div class="example-wrapper" data-iscroll>
<ul data-role="listview" id="ad-list" data-theme="a"></ul>
</div>
</div>
<div data-theme="a" data-role="footer" data-position="fixed">
<div data-role="navbar" >
<ul>
<li><a href="preference.html" data-ajax="false" data-icon="heart" data-iconpos="notext" data-role="button">Change Site</a></li>
<li><a href="#" data-icon="user" data-iconpos="notext" data-role="button">Contact Us</a></li>
<li><a href="content.html" data-ajax="false" data-icon="star" data-iconpos="notext" data-role="button">About</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>
Further finding:
When we looked the DOM after populating the <li>
tag and we found as image below. The <div id="searchads"
has 2 containers one with data-url="/search.html?search=test&submit=
and the other is not.
The <li>
apparently showing up in the first <DIV>
but not in the second one. It looks like the view goes to second instead ?