0
Guys I have a project with apache Cordova running in visual studio, when I try to make a web connection service returns me the error below
Referenceerror: $ is not defined at Childscope.Teste [as WS] (controllers.js:15) at fn (Eval at Compile (Ionic.bundle.js:27643), :4:197) at Ionic.bundle.js:65429 at Childscope.$Eval (Ionic.bundle.js:30400) at Childscope.$apply (Ionic.bundle.js:30500) At Htmlanchorelement. (Ionic.bundle.js:65428) at defaultHandlerWrapper (Ionic.bundle.js:16792) at Htmlanchorelement.eventHandler (Ionic.bundle.js:16780) at triggerMouseEvent (Ionic.bundle.js:2953) at triggerMouseEvent tapClick (Ionic.bundle.js:2942) (Anonymous) @ Ionic.bundle.js:26799 (Anonymous) @ Ionic.bundle.js:23512 $apply @Ionic.bundle.js:30505 (Anonymous) @ Ionic.bundle.js:65428 defaultHandlerWrapper @ Ionic.bundle.js:16792 eventHandler @Ionic.bundle.js:16780 triggerMouseEvent @ Ionic.bundle.js:2953 tapClick @ Ionic.bundle.js:2942 tapTouchEnd @Ionic.bundle.js:3069 _simulateTouchEvent @ripple.js:47 _translateMouseEvent @ripple.js:47
JS and HTML code
angular.module('app.controllers', [])
.controller('loginCtrl', function ($scope, $ionicPopup)
{
$scope.WS = function Teste() {
var webserUrl = "http://example/service.asmx";
var soapRequest =
'<?xml version="1.0" encoding="utf-8"?> \
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> \
<soap:Body> \
<ListarTodosPlanosMarbeg xmlns="http://www.example.com.br" /> \
</soap:Body> \
</soap:Envelope>';
$.ajax({
type: "POST",
url: webserUrl,
contentType: "text/xml",
dataType: "xml",
data: soapRequest,
success: SuccessOccur,
error: ErrorOccur
});
};
function SuccessOccur(data, status, req) {
if (status == "success")
alert(req.responseText);
}
function ErrorOccur(data, status, req) {
alert(req.responseText + " " + status);
}
})
<ion-view title="Login" id="page1" style="background-color:#FFFFFF;">
<ion-content padding="true" scroll="false" class="has-header" ng-controller="loginCtrl">
<script src="../Scripts/jquery-3.1.0.js"></script>
<div>
<img src="img/i1ttvhpETnaA7fesSv1p_LogoGebram.jpg" style="display: block; width: 100%; height: auto; margin-left: auto; margin-right: auto;">
</div>
<div id="login-markdown2" style="text-align:center;" class="show-list-numbers-and-dots">
<p style="color:#000000;">
<strong>Login</strong>
</p>
</div>
<form id="login-form4" class="list">
<label class="item item-input" id="login-input5">
<input type="text" placeholder="CPF/CNPJ" ng-model="CPF_CNPJ">
</label>
<label class="item item-input" id="login-input6">
<input type="text" placeholder="SENHA" ng-model="Senha">
</label>
</form>
<a id="login-button1" class="button button-positive button-block" ng-click="WS()">OK</a>
</ion-content>
</ion-view>
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<style type="text/css">
.platform-ios .manual-ios-statusbar-padding{
padding-top:20px;
}
.manual-remove-top-padding{
padding-top:0px;
}
.manual-remove-top-padding .scroll{
padding-top:0px !important;
}
ion-list.manual-list-fullwidth div.list, .list.card.manual-card-fullwidth {
margin-left:-10px;
margin-right:-10px;
}
ion-list.manual-list-fullwidth div.list > .item, .list.card.manual-card-fullwidth > .item {
border-radius:0px;
border-left:0px;
border-right: 0px;
}
.show-list-numbers-and-dots ul{
list-style-type: disc;
padding-left:40px;
}
.show-list-numbers-and-dots ol{
list-style-type: decimal;
padding-left:40px;
}
</style>
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/routes.js"></script>
<script src="../Scripts/jquery-3.1.1.js"></script>
<script src="js/directives.js"></script>
<script src="js/services.js"></script>
<!-- Only required for Tab projects w/ pages in multiple tabs
<script src="lib/ionicuirouter/ionicUIRouter.js"></script>
-->
</head>
<body ng-app="app" animation="slide-left-right-ios7">
<div>
<div>
<ion-nav-bar class="bar-stable">
<ion-nav-back-button></ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view></ion-nav-view>
</div>
</div>
</body>
</html>
You included the lib
jquery
in the project? According to the error, it is not defined: $ is not defined at Childscope.– Filipe Moraes
yes this included, I have to make some reference of it in the javascript part? me sorry the questions , I am new in this part
– Diego Augusto
added the Solution print where jquery is
– Diego Augusto
Ok, does it exist in the folder, but is it being included in the index or inside your template? Is the controller references the
jquery
but from what I noticed the lib is being included inside your template. Remove and add in index:<script src="../Scripts/jquery-3.1.0.js"></script>
– Filipe Moraes
i removed it from the template and include it in index.html (as I added the code above), but it remains the same error
– Diego Augusto
I created a new project and this error did not appear, but it did: index.html:46 Refused to execute inline Event Handler because it violates the following Content Security Policy Directive: "default-src 'self' data: https://ssl.gstatic.com 'unsafe-Eval'". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline Execution. Note also that 'script-src' was not explicitly set, so 'default-src' is used as a fallback.
– Diego Augusto