将服务器端数据mysql显示给手机WebOS的问题!

时间:2011-06-21 13:25:39

标签: php ajax jquery webos

我是WebOS Dev的新手,刚开始一周之前。所以,需要一点帮助。 从最近2天开始,我遇到了一个问题。 我希望将我的服务器端数据显示给客户端移动,借助palm示例项目,我可以在客户端移动设备上显示静态发布的数据(每次显示相同的发布数据值时显示)。 但是,我想从文本框中发布值(显示通过文本框发布的数据)。

如果你已经安装了webos SDK,那么你可以从这里找到源代码

C:\Program Files\Palm\SDK\share\samplecode\samples\Data\.... 只是尝试运行方法AJAX GET和AJAX POST,我想做一些像AJAX GET方法(Google ex。)

我的修改后的代码是

ajaxPost-assistant.js(我想在此代码中添加文本框并显示此页面发布的数据)

var myassistant = null;
function AjaxPostAssistant()
{

}
AjaxPostAssistant.prototype.setup=function()
{
    myassistant = this;
    this.textFieldAtt = {
            hintText: 'hint',
            textFieldName:  'name', 
            modelProperty:      'original', 
            multiline:      false,
            disabledProperty: 'disabled',
            focus:          true, 
            modifierState:  Mojo.Widget.capsLock,
            limitResize:    false, 
            holdToEnable:  false, 
            focusMode:      Mojo.Widget.focusSelectMode,
            changeOnKeyPress: true,
            textReplacement: false,
            maxLength: 30,
            requiresEnterKey: false
    };
    this.model = {
        'original' : 'Palm',
        disabled: false
    };
    this.controller.setupWidget('sendField', this.textFieldAtt, this.model);
    this.buttonModel1 = {
        buttonLabel : 'Push to send post',
        buttonClass : '',
        disable : false
    }
    this.buttonAtt1 = {
        //type : 'Activity'
    }

    this.controller.setupWidget('post_button',this.buttonAtt1,this.buttonModel1)
    Mojo.Event.listen(this.controller.get('post_button'),Mojo.Event.tap,this.handlePost.bind(this));


}

AjaxPostAssistant.prototype.handlePost=function(event)
{
     var posturl='http://openxcellca.info/Parthvi/webos/ajaxpost1.php';

     var postdata='fname=Ajay';
     var myAjax = new Ajax.Request(posturl, {
        method: 'post',
        evalJSON: 'force',
        postBody: postdata,
        contentType: 'application/x-www-form-urlencoded',
        onComplete: function(transport){
            if (transport.status == 200) 
                myassistant.controller.get('area-to-update').update('Success!');
            else {
                myassistant.controller.get('area-to-update').update('Failure!');
            }
            myassistant.controller.get('server-response').update('Server Response: \n' + transport.responseText);           
        },
        onFailure: function(transport){
            myassistant.controller.get('area-to-update').update('Failure!\n\n' + transport.responseText);
        }
     });

}
AjaxPostAssistant.prototype.activate = function(event) {
    /* put in event handlers here that should only be in effect when this scene is active. For
       example, key handlers that are observing the document */
}


AjaxPostAssistant.prototype.deactivate = function(event) {
    /* remove any event handlers you added in activate and do any other cleanup that should happen before
       this scene is popped or another scene is pushed on top */
}

AjaxPostAssistant.prototype.cleanup = function(event) {
    /* this function should do any cleanup needed before the scene is destroyed as 
       a result of being popped off the scene stack */
}

ajaxPost-scene.htm

<div x-mojo-element="Button" id="post_button"></div>

<div id="area-to-update"></div>
<br>
<div id="server-response"></div>

ajaxpost1.php

<?php
$con = mysql_connect("localhost","user","pwd");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("db", $con);
$qry = "SELECT * FROM user WHERE fname='.$_POST['fname'].'";
$result = mysql_query($qry);
while($row = mysql_fetch_array($result))
  {
  echo "Name:-".$row['fname'];
  echo "<br />";
  echo "E-mail:-".$row['email'];
  echo "<br />";
  echo "Phone:-".$row['phone'];
  echo "<br />";
  }

mysql_close($con);
?>

请帮助我,我想为我的大学项目制作一个同步应用程序。 我需要在这3周内完成。

1 个答案:

答案 0 :(得分:1)

我不是WebOS专家,但首先确保您的php服务器端脚本正在发送JSON。处理回复要清楚得多:请参阅我的问题here

然后它应该很容易。