我是WebOS Dev新手,剛剛在一週前開始工作。所以,需要一點幫助。 從最近2天起,我陷入了一個問題。 我想顯示我的服務器端數據到客戶端手機,在手掌示例項目的幫助下,我能夠在客戶端手機上顯示靜態發佈的數據(每次顯示相同的發佈數據值時)。 但是,我想從文本框(顯示通過文本框發佈的數據)發佈值。問題顯示服務器端數據mysql到手機WebOS!
如果您已經安裝了webOS的SDK,那麼你可以找到從這裏
C:\Program Files\Palm\SDK\share\samplecode\samples\Data\....
的源代碼只是試圖運行這兩個方法AJAX GET和AJAX文章中,我希望做一些事情像AJAX GET方法(谷歌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周內完成。
我對你的問題到底有什麼不確定,但看着你的代碼,它的哪些組件還沒有按你想要的方式工作?服務器端的PHP是否已經做好了正確的事情,只是你不能讓客戶端的JavaScript去做你想做的事情? –