2011-11-23 3 views

답변

5

당신은 자바 스크립트를 통해 HTML5 로컬 스토리지를 사용할 수 있습니다, 여기에 대한 설명 및 튜토리얼에 대한 몇 가지 링크입니다 : http://www.html5rocks.com/en/features/storage

이 ... 이제 응용 프로그램이 클라이언트 기기에 데이터를 저장할 수있는 몇 가지 기술이있다 ..

서버와 상호 작용하려면 서버 측 스크립팅 언어를 사용해야합니다.

//run the following code whenever a new pseudo-page is created 
$(document).delegate('[data-role="page"]', 'pagecreate', function() { 

    //cache this page for later use (inside the AJAX function) 
    var $this = $(this); 

    //make an AJAX call to your PHP script 
    $.getJSON('path_to/server/script.php', function (response) { 

     //create a variable to hold the parsed output from the server 
     var output = []; 

     //if the PHP script returned a success 
     if (response.status == 'success') { 

      //iterate through the response rows 
      for (var key in response.items) { 

       //add each response row to the output variable 
       output.push('<li>' + response.items[key] + '</li>'); 
      } 

     //if the PHP script returned an error 
     } else { 

      //output an error message 
      output.push('<li>No Data Found</li>'); 
     } 

     //append the output to the `data-role="content"` div on this page as a listview and trigger the `create` event on its parent to style the listview 
     $this.children('[data-role="content"]').append('<ul data-role="listview">' + output.join('') + '</ul>').trigger('create'); 
    }); 
}); 

PHP--

<?php 

//include your database connection code 
include_once('database-connection.php'); 

//query your MySQL server for whatever information you want 
$query = mysql_query("SELCT * FROM fake_table WHERE fake_col='fake value'", $db) or trigger_error(mysql_error()); 

//create an output array 
$output = array(); 

//if the MySQL query returned any results 
if (mysql_affected_rows() > 0) { 

    //iterate through the results of your query 
    while ($row = mysql_fetch_assoc($query)) { 

     //add the results of your query to the output variable 
     $output[] = $row; 
    } 

    //send your output to the browser encoded in the JSON format 
    echo json_encode(array('status' => 'success', 'items' => $output)); 
} else { 

    //if no records were found in the database then output an error message encoded in the JSON format 
    echo json_encode(array('status' => 'error', 'items' => $output)); 
} 
?> 

당신은 또한 당신의 PHP 스크립트로 데이터를 전송할 수 있으며,

JS-- : 그것은 당신의 서버와 통신 할 수 AJAX를 사용하여 매우 쉽게 그것을 데이터베이스에 추가하십시오.

jQuery를 .getJSON() : http://api.jquery.com/jquery.getjson

PHP json_encode() : http://www.php.net/json_encode

0

사용 그것은 스토리지의 여러 가지 방법을 제공하며, 실제로 모든 넣을 수 http://westcoastlogic.com/lawnchair/
여기

이상 사용하는 기능에 대한 몇 가지 문서 페이지입니다 브라우저에서 사용할 수있는 첫 번째 어댑터를 가져 오도록 순서대로 어댑터 (저장 방법 옵션)를 지정하십시오. localstorage 또는 sqlite를 사용하려는 경우에도 JSON 형식을 사용하므로 JSON 데이터 만 처리하면됩니다.

0

데이터베이스를 원하면 모바일 브라우저 내부의 SQLLite에 대한 지원이 Web SQL Databases 형태로되어 있으며, 현재 대부분의 Android 및 iPhone 장치에서 지원됩니다.

가 동작하는 예제는 다음 링크를 확인해 보려면 : SQLLite에서 사용할 수있는 SQL 언어보다 더 제한

http://desalasworks.com/html5-databases-on-iphone/

하는 것으로 (내가 가정하는 것은) MySQL 데이터베이스를. 테이블을 작성/삭제하고 선택, 삽입 및 업데이트 할 수 있지만 고급 작업 중 일부는 누락됩니다.

관련 문제