简体   繁体   中英

How to display data from mysql with id sent with javascript ( Adobe Phonegap )

I make a menu link with javascript. By using the parsing in php I display a menu with the help of javascript. The problem is how do I display data in accordance with the "id" which has been on the destination page.

Here's the code in index.html

function loadkategori(idnya){
        $('#contentID').load('kategori.php?id='+idnya, function(){
            $('#myListview').listview().listview('refresh');
        });
    }   

    $(document).ready(function(){
        $.ajax({
            url: 'http://localhost/fiqi/fiqi2/kuliner/www/parsing2.php',
            dataType: 'jsonp',
            jsonp: 'jsoncallback',
            timeout: 5000,
            success: function(data, status){
                $.each(data, function(i,item){
                // $("#listview").append("<li><a href=#><img src="+item.lokasigambar+"><h2>"+item.namatempatnya+"</a><p>Kalimat</p></h2></li>");

                // seharusnya menggunakan class, tidak inline function
                $('#listview').append('<li data-filtertext="form checkboxradio widget checkbox input checkboxes controlgroups" onclick="loadkategori('+item.idkat+')"><a href="" data-ajax="false">'+item.namakategori+'</a></li>');
            });
            // $("#listview");
            // $('ul').listview('refresh');
            $('#listview').listview().listview('refresh');
            // $('#element').collapsibleset('refresh');
            },
            error: function(){
                alert('Error terjadi');
            }
        });
    });

here's the code in kategori.php kategori.php

The code in kategori.php doesn't work on adobe phonegap.

I couldn't implement you code but as far as i understand, You need to use some http request function to get data from serverside php rather than using load(), go for using $.get(). That might work out as a solution to your problem.

function loadkategori(idnya){

    var data = $.get('kategori.php?id='+idnya, function(data,status){
       //PROCESS YOUR DATA OR CALL YOUR FUNCTION TO POPULATE YOUR LISTVIEW
        });
    }   

Secondly you should use either xml or json data for client server communication. That would make your program simple and more efficient. You might paste your php code instead of putting screenshot so that some editing or testing can be done.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM