javascript - Request failing with "No 'Access-Control-Allow-Origin' header" -
i've created form using response (the email client) , trying use ajax on form create custom success/fail message. code works fine. when link ajax form stops working , receive below error message. appreciate help.
error: xmlhttprequest cannot load https://app.getresponse.com/add_subscriber.html. no 'access-control-allow-origin' header present on requested resource. origin 'http://localhost:8888' therefore not allowed access.
<form id="email-form-2" name="email-form-2" accept-charset="utf-8" action="https://app.getresponse.com/add_subscriber.html" method="post"> <input type="text" placeholder="your name" name="name"> <input type="text" placeholder="your email" name="email"> <textarea placeholder="your message..." name="custom_comment"></textarea> <input type="hidden" name="campaign_token" value="xyz" /> <input type="submit" value="send message" data-wait="please wait..."> </form> <div> <p>thanks contacting :)</p> </div> <div> <p>darn. didn't work. give shot , see happens :)</p> </div> <script type="text/javascript"> $(function () { $('#email-form-2').submit(function (e) { e.preventdefault(); $.ajax({ url: this.action, data: $(this).serialize(), type: 'post' }).done(function () { $("#email-form-2+div.w-form-done").show(); $("#email-form-2+div.w-form-fail").hide(); $("#email-form-2").hide(); }) .fail(function () { $("#email-form-2+div.w-form-done").hide(); $("#email-form-2+div.w-form-fail").show(); $("#email-form-2").show(); }); }); }); </script>
okay, suggest use curl
using language prefer in server side. can suggest curl
, php. try in proxy.php
:
<?php // create curl resource $ch = curl_init(); // set url curl_setopt($ch, curlopt_url, "https://app.getresponse.com/add_subscriber.html"); //return transfer string curl_setopt($ch, curlopt_returntransfer, 1); // $output contains output string $output = curl_exec($ch); // close curl resource free system resources curl_close($ch); // output die($output); ?>
and can use proxy.php
in ajax requests in same domain. have way:
<?php die(file_get_contents("https://app.getresponse.com/add_subscriber.html")); ?>
Comments
Post a Comment