Wale
Wale

Reputation: 453

Creating a Mobile application using jquerymobile and php

i have created the login page for my web application using php, where i converted the result into json and grabed the list with jquery. Now my problem is that the list is a hyperlink to another page. So when user selects a name from the list, they should be redicted to another page and see all the information in ragards to that patient. But i dont know how i can grab and display the selected patient on another page.

Ideally i am thinking of creating another function which gets the json results from php file and saves it in an jquery array. Now when the user selects a patient. The id of the patient will then be compared with the one in the list, so if it matches up, then display everything related to that patient but on another page.

var url = 'http://brandon.walesalami.com/nurseD.php';
$.get(url,function (data){
   //var renderHtml = '<div data-role="list-view"></div>';
   var listView = $('<ol data-role="listview" data-inset="true"></ol>');
    for (var i in data.patient)
        {
            var li = $('<li class="patientSel"><a href="#profile" class="' + data.patient[ i ].id + '">' + data.patient[ i ].name + '</a></li>').appendTo(listView);
        }
        $('#co').replaceWith(listView); 
    }, 'json');

Upvotes: 1

Views: 2195

Answers (2)

Gajotres
Gajotres

Reputation: 57309

Take a look at my other answer: jQuery Mobile: Sending data from one page to the another, there you will find several solutions to your problem.

Basically you want something like this: http://jsfiddle.net/Gajotres/eAYB9/

$(document).on('pagebeforeshow', '#index', function(){       
    $('#test-listview li a').each(function(){
        var elementID = $(this).attr('id');      
        $(document).on('click', '#'+elementID, function(event){  
            if(event.handled !== true) // This will prevent event triggering more then once
            {
                localStorage.itemID = elementID; // Save li id into an object, localstorage can also be used, find more about it here: https://stackoverflow.com/questions/14468659/jquery-mobile-document-ready-vs-page-events
                $.mobile.changePage( "#second", { transition: "slide"} );
                event.handled = true;
            }              
        });
    });
});

$(document).on('pagebeforeshow', '#second', function(){       
    $('#second [data-role="content"]').html('You have selected Link' + localStorage.itemID);
});

Upvotes: 1

Ouadie
Ouadie

Reputation: 13185

Just use jQuery Mobile Local Storage,

jQuery Mobile - adding Local Storage
How to use HTML5 local storage with jQuery Mobile

Upvotes: 0

Related Questions