我是WebOS开发人员的新手,一周前刚开始。所以,需要一点帮助。在过去的两天里,我陷入了一个问题。我想将我的服务器端数据显示给客户端移动设备,在palm示例项目的帮助下,我能够在客户端移动设备上显示静态发布的数据(每次显示相同的发布数据值)。但是,我想从文本框中发布值(显示通过文本框发布的数据)
如果你已经安装了webosSDK,那么你可以从这里找到源代码
C:'Program Files'Palm'SDK'share'samplecode'samples'Data'....
只需尝试运行AJAX GET和AJAX POST两种方法,我想做一些类似于AJAX GET方法(Google ex)的事情
我修改过的代码是
ajaxPost-astant.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周内完成。
我不是WebOS专家,但首先要确保php服务器端脚本正在发送JSON。处理回复要清楚得多:请参阅此处的问题
那应该很容易。