jQuery的阿贾克斯POST不工作MailChimp [英] jQuery Ajax POST not working with MailChimp

查看:149
本文介绍了jQuery的阿贾克斯POST不工作MailChimp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code我使用将数据发送到一个MailChimp通讯列表(API第3版)。每次我删除类型:POST 从它试图通过GET发布的数据并将其发送数据正常(在MailChimp API仪表板OK响应)的功能。当浏览器(FF)测试此我得到了真正的响应。第一部分文件。

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.

   $(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");
    }
  })       
 });
});   

林拉我的头发就这一个,任何见解大大AP preciated。

Im pulling my hair out on this one, any insight is greatly appreciated.

在此先感谢,

JN

推荐答案

的主要问题是什么JC在你原来的职位 - 这根本不会由于同源策略问题开展工作。 Firebug是不一样的声音,为什么在GET调用失败,但是这就是为什么它没有返回数据。如果你看,与POST,你会看到火狐甚至没有拨打电话。在另一方面Chrome的JS控制台直接解释同源策略给你。

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.

所有的一切,这是一件非常好的事情,如果比它起价公开发布您的帐户的API密钥,这是一个非常糟糕的事p $ pvents你没有其他原因。如果之所以没有立即下沉,去阅读大量的API中可用的方法,然后认识到,所有你需要访问他们的是,API密钥。

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.

要做到这一点,正确的方法是POST数据回您的服务器,然后从那里发出请求。有几个完全建立PHP的例子(一个使用jquery,偶数),这里

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.

这篇关于jQuery的阿贾克斯POST不工作MailChimp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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