Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8345787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:47:50+00:00 2026-06-09T06:47:50+00:00

I have implemented Phonegap Plugins for v1.0.0. Please have a look at my HTML

  • 0

I have implemented Phonegap Plugins for v1.0.0.
Please have a look at my HTML code

/**** HTML FILE ****/
<!DOCTYPE html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-  scale=1.0, user-scalable=no;" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<script type="text/javascript" charset="utf-8" src="phonegap-1.0.0.js"></script>
<script type="text/javascript" charset="utf-8" src="system.js"></script>
<script type="text/javascript">

var uname = "User1";                    //------------- 2

var System = function() {};

System.prototype.func = function(funcname,funcdata) {

//alert("In the list function");

return PhoneGap.exec(
      null,                 //Success callback from the plugin
      null,                 //Error callback from the plugin
      'SystemPlugin',       //Tell PhoneGap to run     "DirectoryListingPlugin" Plugin
      funcname,             //Tell plugin, which action we want to perform
      funcdata);            //Passing list of args to the plugin
};

PhoneGap.addConstructor(

    function() {

       PhoneGap.addPlugin("system", new System());

    }

);

var _anomFunkMap = {};
var _anomFunkMapNextId = 0; 

function anomToNameFunk(fun)
{
    var funkId = "f" + _anomFunkMapNextId++;
    var funk = function()
    {
        fun.apply(this,arguments);
        _anomFunkMap[funkId] = null;
        delete _anomFunkMap[funkId];    
    }
    _anomFunkMap[funkId] = funk;

    return "_anomFunkMap." + funkId;
}

function GetFunctionName(fn)
{
  if (typeof fn === "function") {
    var name= fn.name;  
    if (!name) {
      var m = fn.toString().match(/^\s*function\s+([^\s\(]+)/);
      name= m && m[1];  
    }
    if (name && (window[name] === fn)) {
        return name;
    } else {
        return anomToNameFunk(fn);
    } 
  }else {
    return null;
  }
}

function post_sync_data(url, urlparam, param, requestheader, callback){

    //alert("In post_sync_data");

    if(undefined == callback){

        if(undefined == requestheader){

            var fnname = GetFunctionName(param);
            var dataArray = [fnname, fnname, url, urlparam];    

        }
        else{

            var fnname = GetFunctionName(requestheader);

            //Note : the param is optional parameter or request header
            var dataArray = [fnname, fnname, url, urlparam, param]; 

        }
    }
    else{

        var fnname = GetFunctionName(callback);
        var dataArray = [fnname, fnname, url, urlparam, param, requestheader];  

    }

    //alert("Calling plugin function post with \r\n"+dataArray);

    var r = window.plugins.system.func("post",dataArray);       
    //alert("r is :\r\n"+r);                                                        ------------- 3

    return r;       
}

function validate(){    

    //Make a webservice call for the Omnesys Token
    post_sync_data(url,urlparam,uname,postDataCB);

}

function postDataCB(token,name){

    //Here uname is undefined.
    alert("In postDataCB()\r\nuname: "+uname+"\r\nuname from C Func: "+name+"\r\n\r\ntoken: "+token);
    return;

}   

function onBodyLoad()
{       
    document.addEventListener("deviceready",onDeviceReady,false);

}

function onDeviceReady()
{
    // do your thing!
    navigator.notification.alert("PhoneGap is working")
    document.getElementById('d1').style.visibility = "visible";
}

</script>
    </head>
    <body onload="onBodyLoad()"> 
<div id="d1" style="visibility:hidden">
    <form>                                                                  <!-- 1 -->
    <button onclick="javascript:validate()">Submit</button><br />   
    </form>
</div>
    </body>
</html>

My Phonegap Plugin File.

/*** My PhoneGap Plugin.xml File ***/
<?xml version="1.0" encoding="utf-8"?>
<plugins>
<plugin name="App" value="com.phonegap.App"/>
<plugin name="Geolocation" value="com.phonegap.GeoBroker"/>
<plugin name="Device" value="com.phonegap.Device"/>
<plugin name="Accelerometer" value="com.phonegap.AccelListener"/>
<plugin name="Compass" value="com.phonegap.CompassListener"/>
<plugin name="Media" value="com.phonegap.AudioHandler"/>
<plugin name="Camera" value="com.phonegap.CameraLauncher"/>
<plugin name="Contacts" value="com.phonegap.ContactManager"/>
<plugin name="Crypto" value="com.phonegap.CryptoHandler"/>
<plugin name="File" value="com.phonegap.FileUtils"/>
<plugin name="Network Status" value="com.phonegap.NetworkManager"/>
<plugin name="Notification" value="com.phonegap.Notification"/>
<plugin name="Storage" value="com.phonegap.Storage"/>
<plugin name="Temperature" value="com.phonegap.TempListener"/>
<plugin name="FileTransfer" value="com.phonegap.FileTransfer"/>
<plugin name="Capture" value="com.phonegap.Capture"/>
<plugin name="SystemPlugin" value="com.phonegap.test.SystemPlugin" />
</plugin>

And my JAVA Class

/** Plugin Code **/
public class SystemPlugin extends Plugin {

@Override
public PluginResult execute(String funcname, JSONArray funcargs, String jscallbackid){

    //Get the success and failure call back functions       
    try{        
        SuccessCallBack = funcargs.getString(0);
        FailureCallBack = funcargs.getString(1);        
    }
    catch (JSONException jsonEx) {

        return null;

    }

    if(funcname.equals("post")){

        try{

            url = funcargs.getString(2);
            urlparam = funcargs.getString(3);               

        }
        catch (JSONException e) {
            SendJS = "javascript:" + FailureCallBack + "('" + e.getMessage() + "')"; 
            sendJavascript(SendJS);
            return null;
        } 

        try {
            conn = new URL(url).openConnection();
            conn.setDoOutput(true);

        } catch (MalformedURLException e) {
            SendJS = "javascript:" + FailureCallBack + "('" + e.getMessage() + "')"; 
            sendJavascript(SendJS);
            return null;
        } catch (IOException e) {
            SendJS = "javascript:" + FailureCallBack + "('" + e.getMessage() + "')"; 
            sendJavascript(SendJS);
            return null;
        }

        if(requestheader == null){

            //Default Request Property
            conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

        }
        else{

            String Headers[] = requestheader.split("\r\n");

            for(i=0; i < Headers.length; i++){

                String hReq[] = Headers[i].split(":");

                if(hReq.length == 2){

                    conn.setRequestProperty(hReq[0], hReq[1]);                  
                }
            }
        }

        try {

            //Blank String
            String data="";

            String param[] = urlparam.split("&");

            for(i=0; i < param.length; i++){

                String keyval[] = param[i].split("=");

                if(keyval.length == 2){

                    data += URLEncoder.encode(keyval[0], "UTF-8") + "=" + URLEncoder.encode(keyval[1], "UTF-8") + "&";
                }
            }

            //remove the unwanted & at the end of the string
            data = data.substring(0,data.length()-1);  

            ro = new OutputStreamWriter(conn.getOutputStream());
            ro.write(data);

            //Close the connection
            ro.close(); 

        } catch (IOException e) {
            SendJS = "javascript:" + FailureCallBack + "('" + e.getMessage() + "')"; 
            sendJavascript(SendJS);
            return null;
        }

        try{

            rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));

            while ((line = rd.readLine()) != null)
            {
                sb.append(line);
            }

            //Close the connection
            rd.close();

        } catch (IOException e) {
            SendJS = "javascript:" + FailureCallBack + "('" + e.getMessage() + "')"; 
            sendJavascript(SendJS);
            return null;
        }

        SendJS = "javascript:" + SuccessCallBack + "('" + JSONObject.quote(sb.toString()); 

        if(jObj != null)
            SendJS += "','" +  jObj + "')";
        else if(StringParam != null)
            SendJS += "','" + StringParam + "')";
        else
            SendJS += "')";

        sendJavascript(SendJS);
        return null;        

    }   
    else{

        return null;

    }       
}
}

Now in the first code you can see numerals 1 2 3
1 – the form element
2 – is a global variable
3 – is the plugin alert

Now if i remove 1. everything works fine. But if i keep the form, the global variable cannot hold its value. It becomes undefined and the alert also gives undefined

Can someone guide me what the issue is ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:47:52+00:00Added an answer on June 9, 2026 at 6:47 am

    This is a Form issue. The form was not as per the standard form format
    Rectifying this fixed the issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented the SortedBindingList class shown at http://www.martinwilley.com/net/code/forms/sortablebindinglist.html I have then successfully added
I have implemented an application using jQuery on PhoneGap. In that I'm using a
I have implemented correctly bump's api, and added this code: - (void) configureBump {
I have implemented a very basic sign up using email address+name, although I would
I have implemented one matrix multiplication with boost::numeric::ublas::matrix (see my full, working boost code
Does phonegap/callback/cordova have a whitelist on all platforms? Is it implemented the same way
I have a simple app developed with jQuery Mobile and implemented in PhoneGap. It
I have implemented a simple file upload-download mechanism. When a user clicks a file
I have successfully implemented facebook connect plugin in android phonegap project with help of
I have a phonegap app and I want to execute Javascript code in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.