how do i call a webservice using phonegap for android - android

How do I make a webservice call from my phonegap app? I found two javascript libraries one from IBM and another IvanWebService http://wiki.phonegap.com/w/page/43725416/SOAP%20Web%20Service that allow you to make such calls but i couldnt get them to run any of my webservices. I am passing in a wsdl link as the service link and i have updated the envelope parameters, still nothing.

If it were me, I would use jQuery.
http://www.bennadel.com/blog/1853-Posting-XML-SOAP-Requests-With-jQuery.htm
http://openlandscape.net/2009/09/25/call-soap-xm-web-services-with-jquery-ajax/
http://weblogs.asp.net/jan/archive/2009/04/09/calling-the-sharepoint-web-services-with-jquery.aspx

<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.css" />
<script src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.js"></script>
<script type="text/javascript">
$(function() {
$("#requestXML").click(function() {
$.ajax({
type: "POST",
url: "http://YOURSITE/script.php",
data: "{}",
cache: false,
dataType: "xml",
success: onSuccess
});
});
$("#resultLog").ajaxError(function(event, request, settings, exception) {
$("#resultLog").html("Error Calling: " + settings.url + "<br />HTTP Code: " + request.status);
});
function onSuccess(data)
{ alert(data);
}
});
</script>
</head>
Button to call the above method:
<input id="requestXML" type="button" value="Request XML" />

Related

Cordova Open PDF in aplication dosn't work Android

I've a problem with open PDF file in my application. I use href on button and windows.open. In browser (chrome) it works. On android not work. How do I set my PDF files opened in the application.
<script src="js/ie-emulation-modes-warning.js"></script>
<link rel="stylesheet" href="css/design.css">
<script type="text/javascript">
$(document).ready(function() {
$.support.cors = true;
$.ajax({
type: "GET",
url: "http://url adres",
dataType: "xml",
crossDomain: true,
success: parseXml
});
function parseXml(xml)
{
$(xml).find("download").each(function() {
$(this).find("item").each(function() {
$("#pobieranie").append('<div class="container-fluid"><div class="row"><div class="col-sm-12 col-xs-12 col-md-12 col-lg-12"><a class="btn btn-primary btn-lg btn-block" href="'+$(this).find('plik').text()+'" id="products">'+$(this).find('name').text()+'</a></div></div></div><br/>');
});
});
window.open("http://urladres.pdf", "_system", "location=yes");
}
});
</script>

How to load a Json link using webview and remove the HTML tags

I have a Json URL am gettings from Wordpress, I want to display the text file using a Webview and format it, but I want to removed the HTMl tags also which display along with the text also.
This is the Json link.
WebView newsfeed = (WebView) findViewById(R.id.webView1);
try{
newsfeed.loadDataWithBaseURL("javascript:(function() { " +"url" +"})()", null, null, null, null);
}catch (Exception e){
e.printStackTrace();
}
So, as per your requirement, your "content" will be obtained using:
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function(){
$.ajax({
url: "http://www.cepfonline.org/features/dyk/?json=1",
type: "GET",
dataType: "jsonp",
success: function (result) {
// alert("success");
var obj = $.parseJSON(JSON.stringify(result));
alert(obj.posts[0].content);
},
error: function () {
alert('Failed');
}
});
});
</script>
</head>
<body>
</body>
</html>
Above code will give you the data of "contents" key:
<p><span style=\"line-height: 1.5em;\">Did you know that our satellite TV Station, LoveWorld plus, can be viewed in over 50 countries of the world?</span></p>\n<p>Did you know that our ministry flagship programs are currently aired in over 180 Television stations worldwide?</p>\n<p>Did you know that through our LoveWorld Radio Ministry, our flagship programs air in over 200 countries across the world?</p>\n<div>Did you know that in the year 2013 alone, the Healing School hosted over 500 Ministers from 42 countries around the world through the Ministers’ visitation programme?</div>\n
Now, using XML parser, you can get the core string data without html tags.
You can also do this, to strip the html tags. Check this out.
Final answer:
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function(){
$.ajax({
url: "http://www.cepfonline.org/features/dyk/?json=1",
type: "GET",
dataType: "jsonp",
success: function (result) {
var obj = $.parseJSON(JSON.stringify(result));
var originalData = obj.posts[0].content;
var strippedData = originalData.replace(/(<([^>]+)>)/ig,"");
alert(strippedData);
},
error: function () {
alert('Failed');
}
});
});
</script>
</head>
<body>
</body>
</html>

phoneGap database creation example

I am trying to create a database using phonegap's api:
In order to do this I have used the following html:
<!DOCTYPE HTML>
<html>
<head>
<title>Cordova</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
var db = window.openDatabase("test", "1.0", "Test DB", 1000000);
alert("database created");
}
</script>
</head>
<body>
<form name="input" action="html_form_action.asp" method="get">
<input type="submit" value="Create Db" />
</form>
</body>
</html>
The buttone doesnt do anyting. The idea is that when the app starts I'm supposed to get confirmation that a database has been created. However this is not happening. Please help...
**Hi check whether Deviceready fires or not then try this **
function onDeviceReady() {
alert("onDeviceReady");
try {
if (!window.openDatabase) {
alert('Browser does not Support this');
} else {
var shortName = 'DbName';
var version = '1.0';
var displayName = 'DBName';
var maxSize = 100000; // in bytes
openDatabase(shortName, version, displayName, maxSize);
alert('DB created');
}
} catch(e) {
if (e == 2) {
// Version mismatch..
console.log("Invalid database version.");
} else {
console.log("Unknown error "+ e +".");
}
return;
}
}
I think there is problem in your js location path . I run your code and i didn't get any error.
Please check your path of your cordova.js . I think you put that js in js folder of assets/www/js
I dont think 'alert()' works inside a webview as-is. Try console.log() instead to output a message (if you are using eclipse), or some other method - perhaps changing the content of a div - to show you the results.

Undefined EXEC method in PhoneGap 2.0

When trying to execute a phonegap plugin method, the application raises this error:
TypeError 'undefined' is not a function (evaluating 'cordova.exec( ...
Code included in app:
Javascript plugin link (file settingswrite.js)
window.SettingsWrite = function(objectData, successCallback, failureCallback) {
var options = {};
for (var key in objectData) {
options[key] = objectData[key];
}
cordova.exec(
successCallback,
failureCallback,
'SettingsWrite',
'set',
new Array(options)
);
};
Javascript code to make use of plugin (file app.js)
function setActualPosition() {
// appMap is an application global object
var map = appMap.getMapEdgesProjection();
window.SettingsWrite([{
x: map.minh,
y: map.maxh
}],
function(r){
alert(r);
},
function(e){
alert("Operation error");
console.log('ERROR: ' + e);
});
}
Plugin is declared in config.xml as:
<plugin name="SettingsWrite" value="es.mycompany.cordova.plugin.SettingsWrite"/>
Javascript code is executed index.html (located at assets folder and included into WebView):
<!DOCTYPE html>
<html>
<head>
<title>Test Mobile</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<script src="assets/js/cordova-2.0.0.js"></script>
<script src="assets/js/jquery-1.7.2.min.js"></script>
<script src="assets/js/settingswrite.js"></script>
<script src="assets/js/app.js"></script>
</head>
<body>
<div id="divMapContainer"></div>
</body>
</html>
And the plugin Java class (as defined in Phonegap docs):
public class SettingsWrite extends Plugin {
public static final String ACTION = "set";
#Override
public PluginResult execute(String action, JSONArray data, String callbackId) {
if(ACTION.equals(action)) {
.
.
.
} else {
.
.
.
}
}
The plugin runs in Android 3.1 device and all needed files are correctly included to the project(cordova-2.0.0.js and cordova-2.0.0.jar). May someone help me?
At what point are you calling setActualPosition? Has the deviceready event fired? If it has not fired, you will not have access to the cordova objects.
I was getting the same error as you. There is a fix in this post:
datePicker plugin not working in Phonegap 2.0

Webservice client to connect SugarCRM web service from PhoneGap

I have SugarCRM Web services in the below link.
http://www.sugarcrm.besplatform.com/soap.php?wsdl
Using web services, I wanted to login and list Leads Management Details through SugarCRM Web Services. I am not able to access SugarCRM web services because of "cross - domain security" issue and "same origin" issue.
I have tried using JSONP , but could not succeed.
I am new to jquery and jsonp. Some one could help me to solve this problem.
Thanks in advance.
using ajax code:
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript">
alert("inside ajax");
var username = "admin";
var password = "admin";
$.ajax({
url: "www.sugarcrm.besplatform.com/soap.php/login",
data: "{'user_name':'" + username + "','password':'" + password + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function(data) {
if (data == null) {
alert( "nothing.");
}
else {
alert(data);
}
},
error: function(e){
alert("failure : "+e);
}
});
using jsonp:
<script type="application/javascript" src="jquery-1.7.2.min.js"></script>
<script type="application/javascript">
var url = "http://www.sugarcrm.besplatform.com/soap.php/login?user_name=admin&password=admin";
jQuery.getJSON(url+"&callback=?", function(data) {
alert("Success" + data.id);
});
</script>
I think you need to send the password MD5 encrypted to Sugar. Also there's a REST WS available at "../service/v2/rest.php" that you could use instead of the SOAP interface.
Since version 6.5.11 this is fixed. If you use "jsoncallback" and then the name it works. Take a look at the file service/core/REST/SugarRestJSON.php to see what changed and patch older versions of sugar

Categories

Resources