javascript - Ajax api 调用总是失败

标签 javascript ajax angularjs onsen-ui

我最近正在使用 Angular.js 和 Onsen 在电话间隙工作。我正在使用 api,但它总是失败。这是我开始的phonegap。

请帮我看看我的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 做了任何错误的代码,请帮助我。

提前致谢

最佳答案

你的代码有问题

url: "URL",

这需要替换为您要调用的网址

示例网址:“www.google.com”

<小时/>

如果您使用 Angular JS,除了使用 Angular JS 对象 ($http) 进行 ajax 调用之外,还有一件事

进行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

关于javascript - Ajax api 调用总是失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27981722/

相关文章:

javascript - 删除 `package-lock.json`快速解决冲突

javascript - 如果字段不为空,则允许 AJAX Post on.click 吗?

javascript - AngularJS:在长时间运行的循环期间强制 DOM 更新(即进度指示器)

AngularJS:注入(inject)具有相同名称但在不同模块下的工厂/服务

javascript - 正则表达式从一行中提取单词

javascript - TypeError : google. maps.MarkerLabel 不是构造函数

javascript - 您可以使用 Django 框架将 Python 用于前端和后端吗?

javascript - 在 WordPress 网站上提交 POST 数据而不刷新?

java - RichFaces 中的服务器端数据表排序

angularjs - 以编程方式在 Kendo 网格 AngularJS 中选择一行