I have the following code I am using to send data to a MailChimp Newsletter List (API v3). Everytime I remove the type: POST
from the function it attempts to post the data via GET and it sends the data properly (ok response in MailChimp API dashboard). When testing this in the browser (FF) I get a .part file with "true" response.
我有下面的代码,用于将数据发送到MailChimp通讯列表(API v3)。每次我删除类型:POST时,它试图通过GET发布数据,并正确地发送数据(在MailChimp API仪表板中,ok响应)。当在浏览器中测试这个时,我得到了一个带有“true”响应的.part文件。
$(function(){
$("a#test").click(function(e){
e.preventDefault()
data = {
"apikey" : "667378947",
"id" : "90298590285",
"email_address" : "test@getmoxied.net",
"output" : "json"
}
$.ajax({
type: "POST",
url: 'http://us2.api.mailchimp.com/1.3/?method=listSubscribe',
data: data,
success: function(data){
alert(data);
},
error: function(){
alert("err");
}
})
});
});
Im pulling my hair out on this one, any insight is greatly appreciated.
我在这个问题上绞尽脑汁,任何见解都将受到极大的赞赏。
Thanks in advance,
提前谢谢,
JN
约
3 个解决方案
#1
8
The main issue is what jc commented on your original post - this simply won't work due to Same Origin Policy issues. Firebug is not as vocal about why the GET call fails, but that's why it returns no data. If you watch that with the POST, you'll see Firefox doesn't even make the call. Chrome's js console on the other hand straight explains the Same Origin policy to you.
主要的问题是jc对你的原始帖子的评论——由于相同的原产地政策问题,这根本行不通。对于GET调用失败的原因,Firebug并不是很明确,但这就是为什么它不返回数据。如果你看了这篇文章,你会发现火狐连电话都没打。另一方面,Chrome的js控制台直接向您解释相同的起源策略。
All in all, this is a very good thing if for no other reason than it prevents you from publicly publishing your account's API Key, which is a very bad thing to do. If the reason why doesn't immediately sink in, go read through the large number of methods available in the API and then realize that all you need to access them is that API Key.
总之,这是一件很好的事情,如果没有别的原因,它阻止你公开你的帐户的API密钥,这是一件很糟糕的事情。如果原因不是立即陷入,请阅读API中大量可用的方法,然后认识到,您需要访问它们的全部是API键。
The correct way to do this is to POST data back to your server, then make the request from there. There are several fully built PHP examples (one using jquery, even), here.
正确的方法是将数据发送回服务器,然后从那里发出请求。这里有几个完全构建的PHP示例(一个使用jquery)。
#2
12
There is an undocumented endpoint that uses JSONP to do cross-domain ajax requests.
有一个未文档化的端点使用JSONP进行跨域ajax请求。
Just change 'post?' to 'post-json?' and add '&c=?' to the end of the standard url to get the JSONP endpoint. This doesn't requires the API key to be exposed on the client-side, or the creation of a server-side view.
只改变的职位?”到“post-json吗?“添加”和c = ?在标准url的末尾获取JSONP端点。这并不需要在客户端公开API密钥,也不需要创建服务器端视图。
I wrote a jQuery plugin that uses this method, if that's useful at all
我编写了一个jQuery插件来使用这个方法,如果它真的有用的话
https://github.com/scdoshi/jquery-ajaxchimp
https://github.com/scdoshi/jquery-ajaxchimp
#3
-2
e.preventDefault();
data = {
"apikey" : "667378947",
"id" : "90298590285",
"email_address" : "test@getmoxied.net",
"output" : "json"
};
Could be? Semicolon is important. Hehe
可以吗?分号是很重要的。呵呵
#1
8
The main issue is what jc commented on your original post - this simply won't work due to Same Origin Policy issues. Firebug is not as vocal about why the GET call fails, but that's why it returns no data. If you watch that with the POST, you'll see Firefox doesn't even make the call. Chrome's js console on the other hand straight explains the Same Origin policy to you.
主要的问题是jc对你的原始帖子的评论——由于相同的原产地政策问题,这根本行不通。对于GET调用失败的原因,Firebug并不是很明确,但这就是为什么它不返回数据。如果你看了这篇文章,你会发现火狐连电话都没打。另一方面,Chrome的js控制台直接向您解释相同的起源策略。
All in all, this is a very good thing if for no other reason than it prevents you from publicly publishing your account's API Key, which is a very bad thing to do. If the reason why doesn't immediately sink in, go read through the large number of methods available in the API and then realize that all you need to access them is that API Key.
总之,这是一件很好的事情,如果没有别的原因,它阻止你公开你的帐户的API密钥,这是一件很糟糕的事情。如果原因不是立即陷入,请阅读API中大量可用的方法,然后认识到,您需要访问它们的全部是API键。
The correct way to do this is to POST data back to your server, then make the request from there. There are several fully built PHP examples (one using jquery, even), here.
正确的方法是将数据发送回服务器,然后从那里发出请求。这里有几个完全构建的PHP示例(一个使用jquery)。
#2
12
There is an undocumented endpoint that uses JSONP to do cross-domain ajax requests.
有一个未文档化的端点使用JSONP进行跨域ajax请求。
Just change 'post?' to 'post-json?' and add '&c=?' to the end of the standard url to get the JSONP endpoint. This doesn't requires the API key to be exposed on the client-side, or the creation of a server-side view.
只改变的职位?”到“post-json吗?“添加”和c = ?在标准url的末尾获取JSONP端点。这并不需要在客户端公开API密钥,也不需要创建服务器端视图。
I wrote a jQuery plugin that uses this method, if that's useful at all
我编写了一个jQuery插件来使用这个方法,如果它真的有用的话
https://github.com/scdoshi/jquery-ajaxchimp
https://github.com/scdoshi/jquery-ajaxchimp
#3
-2
e.preventDefault();
data = {
"apikey" : "667378947",
"id" : "90298590285",
"email_address" : "test@getmoxied.net",
"output" : "json"
};
Could be? Semicolon is important. Hehe
可以吗?分号是很重要的。呵呵