javascript - Couldn't get rid of the multi-origins error when sending an ajax request to mailjet -
i'm trying use mailjet(as mandrill tests weren't successfuls because sent email remained 'queued' , never reach box) mailing service in web application using ajax request :
$.ajax({ // 'type' property sets http method. // value of 'put' or 'delete' trigger preflight request. type: 'post', // url make request to. url: 'https://api.mailjet.com/v3/send/message', contenttype: 'text/plain', data: { 'user': '10ca83...public key 1ccd945:f58e84f9d...private key..8e9502fd7a', 'from': emaildata.email, 'to': 'recipiant@gmail.com', 'subject': 'mailjet test', 'text': emaildata.msg }, xhrfields: { withcredentials: false }, headers: { }, success: function() { // here's handle successful response. }, error: function() { // here's handle error response. // note if error due cors issue, // function still fire, there won't additional // information error. } }).done(function(response) { console.log(response); // if you're sorta thing }); }
as got error in browsers consoles :
index.php:1 xmlhttprequest cannot load https://api.mailjet.com/v3/send/message. no 'access-control-allow-origin' header present on requested resource. origin 'http://localhost' therefore not allowed access. response had http status code 401.
i tried find solution rid of , found 2 solution : 1/ using cors. 2/ found can problem send request local web page runned wamp server , launched app on instead directly in browsers.
but still have error :/ suggestion ? next try google gmail api sending email.
looking @ documentation available in http://dev.mailjet.com - don't think api can used in client-side javascript.
i think, need use server side technology talk api, that's not unreasonable other apis have same requirement.
if you're looking set mailjet, have have written php wrapper https://github.com/mailjet/mailjet-apiv3-php-simple
Comments
Post a Comment