如何在angularjs中使用跨域读取XML文件? [英] How to read the XML file using cross domain in angularjs?

查看:93
本文介绍了如何在angularjs中使用跨域读取XML文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了跨域任务,我有一个包含一些数据的xml文件的url。我的任务是从url即xml文件中获取数据,该文件应该显示在下拉列表中。问题是,我在这里发布的程序允许包含json格式文件的url但是它没有响应xml文件。所以,如果有人帮我这个,我将感激不尽......





--- index.html- -





Hi, I got stuck with the cross domain task, where i have a url of a xml file which consist of some data . My task is to fetch the data from the url i.e, xml file which should be displayed in a drop down list .And the problem is ,the program which i have posted here allows the url which consist json format file but its not responding for the xml file .So, i will be thankful if some one help me with this...


---index.html---


<!DOCTYPE html>
<html ng-app="App">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js">   </script>
  <script src="script.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
  </head>
  <body>
  <div ng-controller="AppCtrl">
    <h1>{{val}}</h1>

   <select ng-options="p.ProductName for p in Product" ng-model="blah"></select>
</div>
</body>
</html>











--- script.js ---












---script.js---



// Code goes here
// Code goes here
var App = angular.module('App',[])
          .controller('AppCtrl', function($scope, AppFact) {
            $scope.val = "Testing the Page For CallsBacks";
            AppFact.getData(function(Product) {
              $scope.Product = Product;
            });
          })
          .factory('AppFact', function($http) {
           return {
             getData: function(successcb) {
            //var url = 'http://filltext.com/?callback=JSON_CALLBACK&rows=10&fname={firstName}&lname={lastName}';
           var url = 'http://xxxxxxxx';
            $http.jsonp(url).
            success(function(Product,status,headers,config) {
              alert(Product);
              console.warn(Product);
              successcb(Product);
            }).
            error(function(Product, status,headers, config) {
              //alert(status);
              //alert("Status is " + status);

            });
             }
                        };
          });



< br $>


// var url ='http://filltext.com/?callback=JSON_CALLBACK&rows=10&fname={firstName}&lname={lastName} '这是一个json网址哪个工作正常。



另一个网址是我需要工作的,它包含xml文件,而且我不想显示原始网址所以我已经给出了var url ='http:// xxxxxxxx'。 Plz帮我理解这个....



这是我的plunker:http://plnkr.co/edit/qq8sELDdZZB5QKe1Pj3T?p =预览




//var url = 'http://filltext.com/?callback=JSON_CALLBACK&rows=10&fname={firstName}&lname={lastName}'this is a json url which works fine .

And the other url is what i needed to be worked and it consist of xml file ,And i'm not suppose to display the original url so i have given as var url = 'http://xxxxxxxx' . Plz help me wit this ....

Here is my plunker:http://plnkr.co/edit/qq8sELDdZZB5QKe1Pj3T?p=preview

推荐答案

范围,AppFact){
scope, AppFact) {


scope.val =测试CallsBacks的页面;
AppFact.getData(function(Product){
scope.val = "Testing the Page For CallsBacks"; AppFact.getData(function(Product) {


scope.Product = Product;
});
})
.factory('AppFact',函数(
scope.Product = Product; }); }) .factory('AppFact', function(


这篇关于如何在angularjs中使用跨域读取XML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆