서버에서 데이터를로드하는 Android webview에 jQuery List View가 있습니다. HTTP GET 응답을 사용하여 서버 데이터베이스에서 데이터를 가져옵니다. 나는 이것을 <body onload="loadRes()">
에서 사용한다. 이것은 나의 방법입니다 :안드로이드와 HTML 사이의 Webview 데이터 불일치 페이지
<script>
lastRecord=0;
function loadRes(){
$('#sample').html('hello');
$.get(
"queryRestaurantsList.php?lastRecord="+lastRecord,
function(data) {
$('#rest_mesgs').append(data)
.listview('refresh');
});
}
</script>
그러나이 목록을 특정 순서로 정렬하고 싶습니다. 이를 위해 나는이 같은 문자열 개체를 포함하는 서버에 안드로이드 코드에서 POST 메시지를 보내
이String list_order ="0012,0002,0003,0001";
이 list_order
String 객체는 기본 키 데이터베이스에 RestaurantID
을 나타냅니다. 이 기본 키의 형식은 VARCHAR(4)
입니다. 클래스 - HttpResponse에
<?
mysql_connect($host,$username,$password);
mysql_select_db($database) or die("Unable to select database");
echo $_POST['ids'];
if($_POST != null){
$query = "SELECT RestaurantID,Name,Short_Loc,Image_Link,Full_Link,Type FROM Restaurant_Info
ORDER BY FIND_IN_SET(RestaurantID,'".$ids."')";
$result = mysql_query($query) or die("Unable to execute query");
while ($row = mysql_fetch_array($result)){
print '<li id="'.$row['RestaurantID'].'" onclick="newAct('.$row['RestaurantID'].')">';
print '<a href="'.$row['Full_Link'].'">';
print '<img style="height:80px;" src="'.$row['Image_Link'].'">';
print '<h2 style="text-wrap : normal" >'.$row['Name'].'</h2>';
print '<p id="type" class="ui-li-aside"><strong>'.$row['Type'].'</strong></p>';
print '<p>'.$row['Short_Loc'].'</p>';
print '</a>';
print '</li>';
}
}
else {
echo "Still working";
}
?>
HttpPostID.class하지만 내가 로그 캣의 정렬 된 목록의 HTML을 볼 수 있지만 난 항상 내 웹보기에 "여전히 작동"라는 메시지를 얻을 그러나이 내 PHP 파일입니다 서버에이 POST 데이터를
public class HttpPostID extends AsyncTask<Void,Integer,Void> {
static String result;
private static final String webphp = "http://...../queryRestaurantsList.php";
String IDs;
HttpPostID(String ids){
this.IDs =ids;
}
@Override
protected Void doInBackground(Void... params){
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(webphp);
try {
String hello="111,222,333";
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("order",IDs));
nameValuePairs.add(new BasicNameValuePair("hello",hello));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
result = EntityUtils.toString(resEntity);
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
내 활동이 전화 : new HttpPostID(tester).execute();
tester
는 String 객체이다.
로그 캣 (단 몇 줄의 출력이 크기 때문에는)
07-12 02:25:14.850: I/System.out(10440): <li id="0013" onclick="newAct(0013)"><a href=""><img style="height:80px;" src="http://cedars.hku.hk/sections/campuslife/images/pacific.jpg"><h2 style="text-wrap : normal" >Pacific Coffee Company</h2><p id="type" class="ui-li-aside"><strong>Sandwiches, Cut cakes, Pies, Pastries, Muffins, Premium Ground Coffee, Fruit Juices</strong></p><p>Main Campus</p></a></li><li id="0003" onclick="newAct(0003)"><a href="#page4"><img style="height:80px;"
먼저 GET을 통해 데이터를 가져온 다음 POST를 통해 같은 데이터를 보내서 정렬 할 것을 의미합니까? – MTahir
@MTahir. 그렇습니다.하지만 채널은 다릅니다. PHP 코드에 POST 요청을 보내고 있습니다. 웹 페이지는 GET 요청에서 해당 PHP 파일을 읽습니다. – stud91
정렬 된 결과를 첫 번째로 반환하거나 앱에서 jQuery를 사용하여 결과를 반환 할 수 있습니다. 예를 들어 [http://stackoverflow.com/questions/1134976/how-may-i-sort-a-list-alphabetically-using-jquery]를 참조하십시오. – MTahir