当使用离子运行-l在设备上测试应用程序时,会发生ajax提交,但$ cordovaSqllite.execute()会抛出错误。
使用离子上传在Ionic View中运行相同的应用程序时,不会发生ajax提交。
controller.js
angular.module('starter.controllers', [])
.controller('IssueCtrl', function($scope,$http,$ionicPopup,$cordovaSQLite) {
var db = $cordovaSQLite.openDB({ name: "my.db" });
var sql ="CREATE TABLE IF NOT EXISTS issues (queryid integer,customer text,contact text,address text,issue text,status text";
$cordovaSQLite.execute(db,sql,[]).then(function(res){});
$scope.processform =function(){
$http({
method : 'POST',
url : 'http://path to my folder/data.php',
data : $.param($scope.formData), // pass in data as strings
headers : { 'Content-Type': 'application/x-www-form-urlencoded' } // set the headers so angular passing info as form data (not request payload)
})
.success(function(data) {
var sql='INSERT INTO issues (queryid, customer,contact,address,issue,status) VALUES ('+data+', "'+$scope.formData.customer+'","'+$scope.formData.contact+'","'+$scope.formData.address+'","'+$scope.formData.issue+'","Open")';
$cordovaSQLite.execute(db,sql,[]).then (function(res){
console.log(res.data);
$ionicPopup.alert({
title: 'Done!',
template: 'Done'
});
});
});
}
issue.html
<ion-view ng-controller="IssueCtrl">
<ion-content scroll="true">
<div class="list">
<form ng-submit="processform()">
<div class="row responsive-sm">
<div class="col">
<label class="item item-input item-floating-label">
<input type="text" ng-model="formData.customer" placeholder="Name" required name="customer">
</label>
</div>
<div class="col">
<label class="item item-input item-floating-label">
<input type="text" ng-model="formData.contact" placeholder="Contact" required name="contact">
</label>
</div>
<div class="col">
<label class="item item-input item-floating-label">
<input type="text" ng-model="formData.device" placeholder="Device" required name="device">
</label>
</div>
</div>
<div class="row responsive-sm">
<div class="col">
<label class="item item-input item-floating-label">
<textarea name="issue" ng-model="formData.issue" id="issue" cols="30" placeholder="Issue" rows="10"></textarea>
</label>
</div>
</div>
<div class="row responsive-sm">
<div class="col">
<input type="submit" class="button button-block button-positive" value="Submit" name="Submit">
</div>
</div>
enter code here
</form>
<pre>
{{ formData }}
</pre>
</div>
</ion-content>
</ion-view>