jquery - simple ajax POST with cross domain request -


i trying send simple form 1 parameter api made back-end programmer, told me need send 1 parameter given url via post using ajax.

the problem no 'access-control-allow-origin' header present error.

i've read through this question , tried implement first answer's solution no success. when test api via hurl works no problem.

this code using send form

    $( document ).ready(function() {         $('.btnenviar').click(function(){             $.ajax({                 type: 'post',                 url: 'http://xxxxx.xxx/subscribers/subscribeemail',                 datatype: 'jsonp',                 async: true,                 success:function(){                     try{                         alert("ok");                     }catch (e){                         alert(e);                     }                 }              });                         });     }); 

and form:

<form class="newsletter" method="post" action="http://xxxxx.xxx/subscribers/subscribeemail">                     <input type="text" placeholder="mail here!" class="input" name="email">                     <input type="submit" class="send pull-right hidden" value="subscribe me!" placeholder="subscribe me!">                     <span class="btnenviar"><i class="fa fa-envelope"></i></span>                 </form> 

there shouldn't php involved in process.

any insights on doing wrong?

try adding crossdomain: true , xhrfields: { withcredentials: true } request:

$( document ).ready(function() {     $('.btnenviar').click(function(){         $.ajax({             type: 'post',             url: 'http://xxxxx.xxx/subscribers/subscribeemail',             datatype: 'jsonp',             async: true,             xhrfields: {                withcredentials: true             },             crossdomain: true,             success:function(){                 try{                     alert("ok");                 }catch (e){                     alert(e);                 }             }          });                     }); }); 

see http://api.jquery.com/jquery.ajax/


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -