开发者

Problem to display server side data mysql to phone WebOS!

开发者 https://www.devze.com 2023-03-14 05:04 出处:网络
I am new to WebOS Dev and just started before a week. So, need a little bit help. From last 2 days I\'m stuck in one problem.

I am new to WebOS Dev and just started before a week. So, need a little bit help. From last 2 days I'm stuck in one problem. I want to display my server side data to client mobile, with the help of palm sample project I am able to display static posted data on client mobile(display every time same posted data values). But, I want to post value from text box(Display data which is posted via textbox).

if you already installed webos SDK then you can find the sourcecode from here

C:\Program Files\Palm\SDK\share\samplecode\samples\Data\.... just try to run both method AJAX GET and AJAX POST , i want to do some thing like in AJAX GET method(Google ex.)

my modified code is

ajaxPost-assistant.js (i want to add textbox in this code and display data which is posted by this page )

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开发者_JAVA技巧 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);
?>

Please help me, I want to make one sync app for my college project. And I need to complete in this 3 weeks.


I'm no WebOS expert, but first make sure that your php server side script is sending JSON. It's much clearer to handle the response: see my question here

Then it should be pretty easy.

0

精彩评论

暂无评论...
验证码 换一张
取 消