2015-01-02 15:05
浏览 54


I am making a college admission application where students can register themselves and after registering the application will immediately open the next page which contains a list of colleges near them. I am developing this application in phonegap. I am fetching the records in JSON format. I have to populate this data in an unsorted dynamic list.

Structure of Student Registration:

The page id is "Registration". When I click the Register button, the Records(Student Info) is inserted and I immediately call page id ListOfColleges in which I have to show the list of Colleges.

<div data-role="page" id="Registration" data-theme="d" style="width: 100%;">        
    <div data-role="main" style="width: 100%;">

        <div  style="width: 76%; margin-left: 10%; margin-top: 3%;" id="studentRegister">
            <input type="text" placeholder="Name" name="userName">
            <input type="text" placeholder="Email" name="eMail">
            <input type="number" placeholder="Mobile" name="mobNumber">
            <input type="number" placeholder="Course" name="Course">
            <a href="#ListOfColleges" class="ui-btn"  id="btnReg" style="background-color: #B6B6BC; color: black;">Register</a>

Structure of List of Colleges Page

 <div data-role="page" id="ListOfColleges">     
            <div style="width: 100%; margin-top:21%; margin-left: 1%; color: black;">
                <ul data-role="listview">


Format of JSON Data and php Code

header('Access-Control-Allow-Origin: *');//Should work in Cross Domaim ajax Calling request
        $query="Select * from collages";
            while($recipe=mysql_fetch_array($result, MYSQL_ASSOC)){
            echo $output;
    echo "Invalid format";

I am trying to write the following JavaScript to populate the "ListOfColleges" page. "btnReg" is the id of the button on the page Registration.

Please help me to write this script and suggestions for modification of structure are welcome..


                      data:{type:"login", UserName:userId,Password:userPassword}, 
                      success: function(response){    
                              // *Logic for populate the dynamic list*

                      error: function(err){ 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongtu4028 2015-01-02 18:59

    I should look for tutorials but here is a guide...

    in the HTML, add an ID to the ListView:

    <ul id="listCollege" data-role="listview">

    Then in the Javascript button click function do the following Loop:

    for (i=0; i< iElements; i++)
      $("#listCollege").append("<li><a href=''>College 1</a></li>");

    Obviously you have to create the "li" element with the json data... but that's the text structure.

    Some JQMobile versions or in some cases you may need to add AFTER THE "FOR LOOP" the following:


    but sometimes you don't have to, and if you write it YOUR CODE WILL FAIL, so take into account to try WITH or WITHOUT the listview("refresh") instruction.

    Hope it helps!

    点赞 打赏 评论

相关推荐 更多相似问题