简体   繁体   English

Javascript-用于从URL加载xml数据

[英]Javascript - use to load xml data from URL

I have this url with some xml data in it: 我有这个网址,其中包含一些xml数据:

http://64.182.231.116/~spencerf/union_college/Upperclass_Sample_Menu.xml

And I would like to load this xml data into my javascript script so I can parse it. 而且我想将此xml数据加载到我的JavaScript脚本中,以便我可以对其进行解析。 I am using parse.com Javascript SDK, in there cloud code. 我在其中使用云代码的parse.com Javascript SDK。

jQuery seems either not to work with Parse cloud code, or I cannot get it to work. jQuery似乎无法与Parse云代码一起使用,或者我无法使其正常工作。 So is there a way to load the xml data (xml tree), with javascript without using jQuery? 那么有没有办法在不使用jQuery的情况下使用javascript加载xml数据(xml树)?


THIS IS NOT WORKING, I DONT THINK IT CAN WORK 这不起作用,我不认为它可以工作


Here is the code I have tried: 这是我尝试过的代码:

Parse.Cloud.define("next", function(request, response) {
  response.success("Hello world!");

  $.ajax({
    url: 'http://64.182.231.116/~spencerf/union_college/Upperclass_Sample_Menu.xml', // name of file you want to parse
    dataType: "xml", // type of file you are trying to read
    success: parse, // name of the function to call upon success
    error: function(){alert("Error: Something went wrong");}
  });
});

But when I run this I get an error: 但是当我运行它时,我得到一个错误:

$ is not defined

at main.js: 在main.js上:

I do not know how parse.com works but $ refers to jQuery and it seems that it is not included, at least at the time that you run your script. 我不知道parse.com的工作原理,但是$表示jQuery,并且似乎不包含jQuery,至少在运行脚本时是这样。

Maybe try this jQuery wrapper for parse.com https://github.com/srhyne/jQuery-Parse 也许尝试这个parse.com的jQuery包装器https://github.com/srhyne/jQuery-Parse

use a j query wrapper 使用j query包装器

$.ajax({
url: 'http://64.182.231.116/~spencerf/union_college/Upperclass_Sample_Menu.xml', // name of file you want to parse
dataType: "xml", // type of file you are trying to read
success: parse, // name of the function to call upon success
error: function(){alert("Error: Something went wrong");}

}); });

This should help you 这应该对你有帮助

url: 'http://64.182.231.116/~spencerf/union_college/Upperclass_Sample_Menu.xml', // name of file you want to parse
dataType: "xml", // type of file you are trying to read
success: parse, // name of the function to call upon success
error: function(){alert("Error: Something went wrong");}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM