Sendgrid API-JSON调用 [英] Sendgrid API - JSON call

查看:278
本文介绍了Sendgrid API-JSON调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从SendGrid API接收数据

I'm trying to receive data from SendGrid API

$.ajax({
    type:'GET',
    url:"https://sendgrid.com/api/bounces.get.json",
    data: {api_user:'username',api_key:'userkey',date:1},
    success: function(data){    
        console.log(data)       
    },
    crossDomain: true,
    dataType: 'jsonp',
    error:function(a,b,c){
        console.log(a);
    }
}); 

控制台显示:

对象{readyState = 4,status = 200,statusText ="success"}

Object { readyState=4, status=200, statusText="success"}

parsererror

parsererror

错误:未调用jQuery17208301184673423685_1374648217666

Error: jQuery17208301184673423685_1374648217666 was not called

错误或问题在哪里?

推荐答案

问题是SendGrid不支持jsonp.

The issue is that SendGrid does not support jsonp.

不幸的是,切换到纯JSON也不起作用,因为SendGrid没有CORS标头,浏览器也不允许您访问页面.简而言之,您不能直接向SendGrid发出AJAX请求.

Unfortunately, switching to plain JSON will not work either, as SendGrid has no CORS headers and browsers will not allow you to access the pages. In short you cannot make AJAX requests dorectly to SendGrid.

但是,通常情况会更好,因为所有SendGrid端点都需要身份验证,并且在AJAX请求中包含您的用户名和密码将允许用户使用它们,然后使用它们发送电子邮件.

However, generally this is for the better as all SendGrid endpoints require authentication and having your username and password in an AJAX request would allow users to take them and then use them to send email.

要在前端获取这些统计信息,您需要一台服务器来获取它们并将其输出到您的域或具有CORS配额的域中.

To get these stats on the frontend, you'll need a server to get them and output them on your domain or a domain with CORS allowances.

这篇关于Sendgrid API-JSON调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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