Apologies if this is elementary. I'm primarily a front end designer/dev.
如果这是基本的,请道歉。我主要是前端设计师/开发人员。
I have webform through a form service called wufoo.
我通过名为wufoo的表单服务进行webform。
Wufoo generates a lovely XML (or json) file that can be grabed and parsed.
Wufoo生成一个可以被抓取和解析的可爱的XML(或json)文件。
I'm trying to grab the entries xml feed that is associated with the form and parse it via jquery to show who has entered.
我正在尝试获取与表单关联的条目xml提要并通过jquery解析它以显示谁已进入。
Im using the following code (which works with a local xml file).
我使用以下代码(使用本地xml文件)。
http://bostonwebsitemakeover.com/2/test.html
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
<script>
$(document).ready(function () {
$.ajax({
type: "GET",
url: "people.xml",
dataType: "xml",
success: xmlParser
});
});
function xmlParser(xml) {
$('#load').fadeOut();
$(xml).find("Entry").each(function () {
$(".main").append('<div class="entry">' + $(this).find("Field1").text() + ' ' + $(this).find("Field2").text() + ' http://twitter.com/' + $(this).find("Field17").text() + '</div>');
$(".entry").fadeIn(1000);
});
}
</script>
My XML file contains the following:
我的XML文件包含以下内容:
<?xml version="1.0"?>
<Entries>
<Entry>
<EntryId>1</EntryId>
<Field1>Meaghan</Field1>
<Field2>Severson</Field2>
<Field17/>
</Entry>
<Entry>
<EntryId>2</EntryId>
<Field1>Michael</Field1>
<Field2>Flint</Field2>
<Field17>michaelflint</Field17>
</Entry>
<Entry>
<EntryId>3</EntryId>
<Field1>Niki</Field1>
<Field2>Brown</Field2>
<Field17>nikibrown</Field17>
</Entry>
<Entry>
<EntryId>4</EntryId>
<Field1>Niki</Field1>
<Field2>Brown</Field2>
<Field17>nikibrown</Field17>
</Entry>
</Entries>
I'm wondering how I would do this with the xml file hosted on the wufoo (which is https)
我想知道如何使用wufoo上托管的xml文件(这是https)
So I guess Im asking how do I authenticate the feed via jquery? Or do i need to do this via json? Could someone explain how?
所以我想我问我如何通过jquery验证feed?或者我需要通过json做到这一点?有人可以解释一下吗?
2 个解决方案
#1
1
The problem is the same-origin policy. This is a rule, enforced by all browsers, that you cannot use XMLHTTPRequest (the basis for AJAX) cross-domain. You may not make requests to another server, or to the same server if it uses a different port or protocol (http/https, for example).
问题是同源政策。这是由所有浏览器强制执行的规则,您不能使用XMLHTTPRequest(AJAX的基础)跨域。如果它使用不同的端口或协议(例如,http / https),则不能向其他服务器或同一服务器发出请求。
The most plausible solution is to set up a script on your web server that proxies the XML file for your application. In PHP, for instance, it could be as simple as:
最合理的解决方案是在Web服务器上设置一个代理应用程序XML文件的脚本。例如,在PHP中,它可以像下面这样简单:
<?php
header('Content-Type: application/xml');
echo file_get_contents('the wufoo url');
?>
You could then call the file with AJAX and receive the contents of the remote file.
然后,您可以使用AJAX调用该文件并接收远程文件的内容。
#2
0
jQuery allows for a username and password to be passed into the ajax call:
jQuery允许将用户名和密码传递给ajax调用:
$(document).ready(function () {
$.ajax({
type: "GET",
url: "people.xml",
dataType: "xml",
success: xmlParser,
username: "myUsername"
password: "myPassword"
});
});
However this puts you username and password in plain text in your js. You may want to think about setting up a little php proxy to make the authenticated call so that all your credentials are only on the server.
但是,这会在js中以纯文本形式显示用户名和密码。您可能需要考虑设置一个小的PHP代理来进行经过身份验证的调用,以便您的所有凭据都只在服务器上。
#1
1
The problem is the same-origin policy. This is a rule, enforced by all browsers, that you cannot use XMLHTTPRequest (the basis for AJAX) cross-domain. You may not make requests to another server, or to the same server if it uses a different port or protocol (http/https, for example).
问题是同源政策。这是由所有浏览器强制执行的规则,您不能使用XMLHTTPRequest(AJAX的基础)跨域。如果它使用不同的端口或协议(例如,http / https),则不能向其他服务器或同一服务器发出请求。
The most plausible solution is to set up a script on your web server that proxies the XML file for your application. In PHP, for instance, it could be as simple as:
最合理的解决方案是在Web服务器上设置一个代理应用程序XML文件的脚本。例如,在PHP中,它可以像下面这样简单:
<?php
header('Content-Type: application/xml');
echo file_get_contents('the wufoo url');
?>
You could then call the file with AJAX and receive the contents of the remote file.
然后,您可以使用AJAX调用该文件并接收远程文件的内容。
#2
0
jQuery allows for a username and password to be passed into the ajax call:
jQuery允许将用户名和密码传递给ajax调用:
$(document).ready(function () {
$.ajax({
type: "GET",
url: "people.xml",
dataType: "xml",
success: xmlParser,
username: "myUsername"
password: "myPassword"
});
});
However this puts you username and password in plain text in your js. You may want to think about setting up a little php proxy to make the authenticated call so that all your credentials are only on the server.
但是,这会在js中以纯文本形式显示用户名和密码。您可能需要考虑设置一个小的PHP代理来进行经过身份验证的调用,以便您的所有凭据都只在服务器上。