我最近使用Angular.js和Onsen在手机间隙工作。我正在使用api,它总是失败。这是我开始的电话。
请帮我解决我的java脚本中出了什么问题。
我的java脚本代码: -
<script>
var app = angular.module('myApp', ['onsen']);
var values="<?xml version='1.0'?><root><Email>Email/Email><UserPW>Password</UserPW><Method>ValidateUser</Method></root>";
var yourApp = angular.module('myApp', ['onsen.directives']);
yourApp.controller("PageContrrol", function($scope) {
$scope.Check = function(){
var name = document.getElementById("searchName");
var pass = document.getElementById("searchPass");
var NAME_VALUE=name.value;
var PASS_VALUE=pass.value;
var NM_LG=NAME_VALUE.length;
var PS_LG=PASS_VALUE.length;
if(NM_LG != 0 && PS_LG != 0){
// alert("Name is !"+NAME_VALUE);
//$scope.Login = function() {};
$.ajax({
url: "URL",
type: "post",
data: values,
contentType: "application/xml; charset=utf-8",
dataType: "xml",
success: function(){
alert("success");
$("#result").html('Submitted successfully');
},
error:function(){
alert("failure");
$("#result").html('There is error while submit');
}
});
}else{
alert("Please enter name or password!");
}
}
});
app.controller('PageController', function($scope) {
var options = $scope.myNavigator.getCurrentPage().options;
console.log(myNavigator.getPages().length);
console.log(options);
});
</script>
如果我为ajax做了错误的代码,请帮助我。
提前致谢
答案 0 :(得分:2)
代码中的问题
url: "URL",
这需要替换为您要调用的网址
exampole url: "www.google.com"
进行ajax调用的示例是
var req = {
method: 'POST',
url: 'http://example.com',
headers: {
'Content-Type': undefined
},
data: { test: 'test' },
}
$http(req).success(function(){...}).error(function(){...});
在此处阅读更多内容:https://docs.angularjs.org/api/ng/service/ $ http