• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

POST jquery not working

dejan

Lurker
Feb 17, 2015
3
0
Hello,

I'm newly and I want to ask you how to use POST jquery from cordova apache? From browser works, but in android device not working.
<!DOCTYPE html>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<html>
<head>
<!--
Customize this policy to fit your own app's needs. For more guidance, see:
https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
Some notes:
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
* Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
* Enable inline JS: add 'unsafe-inline' to default-src
-->
<!--<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;>-->
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="initial-scale=1, width=device-width, viewport-fit=cover">
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>Hello World</title>
</head>
<body>
<div class="app">
<h1>Apache Cordova</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>
<script type="text/javascript" src="js/jquery.cookie.min.js"></script>
<script type="text/javascript" src="js/datatables.min.js"></script>

<script>
function getUrlVars() {
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
hash = hashes.split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}



$(document).ready(function () {
$("#dvTest").click(function () {


$.ajax({
type: "POST",
url: "http://www.domainname/webservice/login.asmx/prijava",
// data: JSON.stringify({ username: "desoft1", password: "+UvML^cIAjFL}4" }),
// contentType: "application/json; charset=utf-8",
// dataType: "json",
success: function (data) {

alert("30");

var json = data.d;

$('#example').DataTable({
"data": JSON.parse(json),
"columns": [
{ "data": "Id" },
{ "data": "Company" }
]
});

$('#example tbody').on('click', 'tr', function () {
var table = $('#example').DataTable();

var data = table.row(this).data();
$.cookie("IdCompany", data.Id);


});
},
failure: function (msg) {
alert(msg.d);
}
});
});
});
</script>
<br /><br />
<div id="dvTest">TEST121</div>


<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Id</th>
<th>Company</th>
</tr>
</thead>
</table>

</body>
</html>



config.xml:
<?xml version='1.0' encoding='utf-8'?>
<widget id="pn" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>pn</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev@cordova.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html" />
<plugin name="cordova-plugin-whitelist" spec="1" />
<access origin="*" />
<access origin="*" subdomains="true"/>
<allow-navigation href="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
<resource-file src="platforms/android/app/src/main/AndroidManifest.xml" target="AndroidManifest.xml" />
</widget>

AndroidMainfest.xml:
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:usesCleartextTraffic="true" android:versionCode="10000" android:versionName="1.0.0" package="pn" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:hardwareAccelerated="true" android:icon="@Mipmap/ic_launcher" android:label="@String/app_name" android:supportsRtl="true">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:label="@String/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@String/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>



Thank you for your help.
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones