douba2011 2013-04-17 17:07
浏览 43

如何更好地编写将PHP外部数据添加到jquery选择

I want to submit an app using phonegap, My app uses a lot of php which i know apple do not like so much and just decline the app and say its best to have a web app. I have an example index.html here

<!DOCTYPE HTML>
<html>
<head>
      <meta charset="utf-8" />
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <meta name="apple-mobile-web-app-status-bar-style" content="black" />
        <title>
        </title>
        <link rel="stylesheet" href="css/logout-button.min.css" />
         <link rel="stylesheet" href="css/jquery.mobile-1.3.0.min.css" />
        <link rel="stylesheet" href="css/my.css" />
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        </script>
        <script src="js/jquery.mobile-1.3.0.min.js"></script>
        <script src="js/jquery.cookies.2.2.0.min.js"></script>


<script type="text/javascript">
var uid = $.cookies.get( 'uid' );
 if(uid == null)
                 {
                window.location ='account-login.html'; }
                 else
                 { }
</script>
</head>

<body>
<div data-role="page" id="index4">

           <div data-theme="a" data-role="header">
        <a data-role="button" data-direction="reverse" data-rel="back" data-transition="slide"
         data-icon="arrow-l" data-iconpos="left" class="ui-btn-left">
            Back
        </a>
        <h3>
           Event Details
        </h3>
    </div>

         <div data-role="content">
             <form id="eventForm" name="eventForm">
                    <div data-role="fieldcontain">
                        <fieldset data-role="controlgroup">
                            <label for="event">
                                Event
                            </label>
                            <input name="eventname" id="eventname" placeholder="eventname" value="" type="text" />
                        </fieldset>
                    </div>
                    <div data-role="fieldcontain">
                        <fieldset data-role="controlgroup">
                            <label for="about">
                                About
                            </label>
                            <textarea name="about" id="about" placeholder="about" value=""></textarea>
                        </fieldset>
                    </div>
                    <div data-role="fieldcontain">
                    <label for="dates">
                                Choose Dates
                            </label>
                            <div id="with-altField"></div>
                            <input type="hidden" id="altField" name="dates">
                        </fieldset>
                    </div>
                    <div data-role="fieldcontain">
                        <fieldset data-role="controlgroup">
                            <label for="enddate">
                                End Date
                            </label>
                            <div id="with-altfield1"></div>
                            <input type="hidden" id="altField1" name="enddate">
                        </fieldset>
                    </div>
                    <div data-role="fieldcontain">
                        <script>
                            $.get('event-details.php', function(data){
                            $('#yourdiv').html(data);
                            });
                        </script>   
                        <div id="yourdiv"></div>
                    </div>
                    <div data-role="fieldcontain">
                        <label for="manual">Add Emails</label>
                        <textarea cols="40" rows="8" name="emails" id="emails"></textarea>
                    </div>
                        <input type="submit" value="Submit" id="submitEventButton">
                </form>
        </div>
</div>  
</body>
</html>

I call event-details.php here

<?
require_once("../backend/functions.php");
dbconn();
                            $id = $CURUSER["id"];
                            $res = "SELECT username,email,status FROM users left join cal_contacts on cal_contacts.contactid = users.id WHERE cal_contacts.userid = $id";
                            $res1 = mysql_query($res);
                        ?>
                        <label for="select-choice-1" class="select">
                                Choose Contacts:
                            </label>
                            <select name="contacts[]" id="contacts" multiple="multiple" data-native-menu="false">
                        <?
                            while($row = mysql_fetch_array($res1))
                            { 
                            print "<option value=$row[email]>$row[email] ($row[status])</option>";
                            }
                        ?>
                        </select>
                        <?

I have the select-menu created through php. I was wondering if there was another way to do this so the complete select html doesn't have to be on the php script. This would mean that it would be harder for me to change my app once submitted and i'm sure apple would accept it alot easier.

  • 写回答

1条回答 默认 最新

  • dongzhuang6177 2013-04-17 18:09
    关注

    If your problem is just to remove the PHP processing on that HTML, you could just move it somewhere else as a web service then get it via ajax request. Then you can just use json, etc. to fetch the data and populate your select menu.

    here is a doc on jquery! regarding how to make ajax requests.

    i found a tutorial here which seem similar on what you want to achieve.

    How To Write A Simple PHP/MySQL Web Service for an iOS App!

    评论

报告相同问题?

悬赏问题

  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构