Uzak bir veritabanının kullanımına büyük ölçüde bağlı olacak bir Android uygulaması geliştiren bir ekipteyim. PhoneGap ve Jquery Mobile kullanıyoruz ve AJAX ve JSON çağrılarını kullanarak MySQL veritabanımıza bağlanmaya çalışıyoruz. Şu anda test fazımızda sorun yaşıyoruz, bu da MySQL Workbench üzerinden mySQL/input'dan kodlanmış bir "Ted" kullanıcısını çekerek bile bir bağlantımız olduğunu doğrulamaktır. elimizdeki kadarıylaPhoneGap, AJAX ve JQuery Mobile kullanarak bir MySQL veritabanına bağlanma
, veri iletimi süreci bu şekilde çalışır:
bizim html dosyası üzerinde, elimizdeki Connect.js komut dosyasını çalıştırmak gereken bir
<script type="text/javascript" src="Connect.js"></script>
^Hangi , doğru mu? Yani oradan, Connect.js koştu mu?
Connect.js, harici bir web hizmetinde barındırılan ve MySQL veritabanına bağlanmak ve bilgi almak için PHP'yi çalıştırmasına izin veren ServerFile.php sunucumuza bağlayarak çalışır. İşte
//run the following code whenever a new pseudo-page is created $('#PAGENAME').live('pageshow', function(event)) { // cache this page for later use (inside the AJAX function) var $this = $(this); // make an AJAX call to your PHP script $.getJSON('http://www.WEBSITENAME.com/ServerFile.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'); }); });
Kodda sorunun nerede olduğunu belirlemek için herhangi bir hata ayıklama işlemi yaptınız mı? Echo json_encode (array ('status' => 'success')); SQL Server ile bir yere boğulma sorunu olup olmadığını görmek için ServerFile.php açılışında, ya da geri geliyor ne okuma ile ilgili bir sorun. –
Veya hata ayıklamanın başka bir yolu, $ .getJSON işlevinin içinde '' console.log (yanıtı) koymak olabilir. Yanıt, Firebug'ınızda görünecektir. –