Thursday, 15 May 2014

android - Can't Find variable in Phonegap using javascript -



android - Can't Find variable in Phonegap using javascript -

when run programme on browser getting response fail, run in android phone getting reference error can't find variable data. code works in emulator also. help me

<html> <head> <script type="text/javascript" charset="utf-8" src="phonegap-1.0.0.js"></script> <script type="text/javascript" charset="utf-8" src="cordova-2.4.0.js"></script> <script type = "text/javascript"> function getresponse(){ var url = "http://www.apexweb.co.in/apex_quote/phone_gap/uname_validation.asp?un=9999999999&pwd=123456789&callback=your_callback"; var head= document.getelementsbytagname('head')[0]; var script= document.createelement('script'); script.type= 'text/javascript'; script.src= url; head.appendchild(script); your_callback(data); //here getting reference error, can't find variable info } function your_callback(data){ var st = data.status; alert(st); } </script> </head> <body> <button input type = "button" onclick = "getresponse()"> getresponse </button> </body> </html>

whatever understood code have added code in it, please check reply below:

i have added info variable declaration , value it.

<script type = "text/javascript"> var data=""; // declare varible here can variable in both function. function getresponse(){ var url = "http://www.apexweb.co.in/apex_quote/phone_gap/uname_validation.asp?un=9999999999&pwd=123456789&callback=your_callback"; var head= document.getelementsbytagname('head')[0]; var script= document.createelement('script'); script.type= 'text/javascript'; script.src= url; info = head.appendchild(script); // script value in info variable your_callback(data); //here getting reference error, can't find variable info } function your_callback(data){ var st = data.value; alert('script value is: '+st); } </script>

make sure have set html file in assest/www folder & code:

by using web view can utilize java script , html page.

public class mainactivity extends activity { webview webview; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); webview = (webview)findviewbyid(r.id.webview); webview.getsettings().setjavascriptenabled(true); webview.setwebchromeclient(new webchromeclient()); webview.loadurl("file:///android_asset/www/index.html"); // webview.loadurl("webappdemo/assets/www/index.html"); } }

javascript android jquery cordova jquery-mobile

No comments:

Post a Comment