2

私はアンドロイドでのフォンギャップ開発が初めてです。私は phonegap アプリケーションに取り組んでいます。form タグを使用してサーバーにコードを送信しました。今、私は結果を取り戻したいと思っています。サーバーから返された結果を取得する方法を教えてください。結果は JSON 形式です。

これは、HTMLファイルでフォームを送信するために使用しているコードです。

    <form id="signUpform" action="http://web1.xxx.com/sss/signup.php" method="post" 
    onsubmit="return( validate() );">
    <div style="float:left; width: 100%; height: inherit;">
        <h3>New Client</h3>
    </div>
    <br />
    <div style="float:left; width: 80%; height: inherit; margin-top: 5px;">
        <div style="float:left; width: 40%; height: inherit; margin-top: 5px; padding-top: 8px;">
             <label>UserName </label></div>
        <div style="float:right; width: 60%; height: inherit;">
            <input id="UserUsername" type="text" name="username" /></div>
    </div>
    <br />  
    <div style="float:left; width: 80%; height: inherit; margin-top: 5px;">
        <div style="float:left; width: 40%; height: inherit; margin-top: 5px; padding-top: 8px;">
            <label>Password </label></div>
        <div style="float:right; width: 60%; height: inherit;">
            <input id="pass" type="text" name="password" /></div>
    </div>
    <br />
    <div style="float:left; width: 80%; height: inherit; margin-top: 5px;;">
        <div style="float:left; width: 40%; height: inherit; margin-top: 5px; padding-top: 8px;">
            <label>   Confirm Password </label></div>
        <div style="float:right; width: 60%; height: inherit;">
            <input id="cpass" type="text" name="confirm_password" /></div>
    </div>
    <br />
    <div style="vertical-align:middle; float:left; width: 80%; height: inherit; margin-top: 5px;">
        <div style="float:left; width: 40%; height: inherit; margin-top: 5px; padding-top: 8px;">
            <label> Email ID </label></div>
        <div style="float:right; width: 60%; height: inherit;">
            <input id="UserEmail" type="text" name="email" /></div>
    </div>
    <br />
    <div style="float:left; width: 80%; height: inherit; margin-top: 5px;">
        <div style="float:right; width: 100%; height: inherit;">
            <input type="submit" value="Get Started"/> </div>
    </div>
</form>   

フォームがサーバーに送信されます。結果を JSON 形式で返します。結果は次のとおりです。

{"UserID":"220"} 

これは、フォームを送信した後にデバイスに印刷されます。

この値を取得する方法を教えてください。

前もって感謝します

4

3 に答える 3

2
 var urlStr = URL1 + "username=" + username + "&password=" + password;

 jQuery.support.cors = true;
 $.ajax({
     type: "GET",
     crossDomain: true,
     contentType: "application/json; charset=utf-8",
     url: urlStr,
     data: "{}",
     dataType: "json",
     timeout: 5000,
     success: ajaxCallSucceed,
     error: ajaxCallFailed
 });

function ajaxCallSucceed(json){
 //  success
 }

function ajaxCallFailed(json){
 // failed
}
于 2013-07-02T05:39:50.983 に答える
1

リモート サーバーにリクエストを送信するには、jQuery.ajaxを使用します。

サンプルコードは

function FetchData() {
    $.ajax({
        async: false,
        type: "POST",
        url: "Your_URL",
        dataType: "json",
        success: function (data, textStatus, jqXHR) {


            $.each(data, function (i, object) {
                alert(obj.Data);
            });

        },
        error: function () {
            alert("There was an error loading the feed");
        }
    });
}

onclickボタンのこの関数を呼び出します。

それが役立つことを願っています。

于 2013-07-02T05:32:22.300 に答える