Ajax JQuery cross domain form submission

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I want to submit a form with Ajax jquery,

http://domain2.com http://domain2.com

This is my form

    <form action="https://domain2.com/index.php/site/send_sms" method="post">

<input type="hidden" name="with_slogan" value="yes" id="with_slogan" />


<input type="hidden" name="glist" id="glist" value="" />



Number: <br/>
<input type="text" name="to_mobile" value="" id="to_mobile" class="hide" />

<br/>


Message: (100 text) <br/>
<textarea cols="30" rows="6" maxlength="110" name="sms_body" id="sms_body"> --shaikatssj </textarea>



<br/>

<input type="submit" name="submit" value="Send" class="sm-button-submit" /></form>

Ajax:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>   

<script> var url="https://domain2.com/index.php/site/send_sms";  var datastring = "with_slogan=yes&glist=&to_mobile=017147974&sms_body=teshejdsgjkjfdt&submit=submit";  $.ajax({     url: url,     data: datastring,     type: "POST",     crossDomain: true,     success: function(e) {         alert(e.responseText);     },     error: function(XMLHttpRequest, textStatus, errorThrown) {          alert("Status: " + textStatus); alert("Error: " + errorThrown);      } });  </script>

I tried ajax post but gained zero success.

Answers

    • first in your form you dont need action and method post you are sending it via ajax script so delete it
    • Add form id form id= form

Try using this script:

$( #form ).on( submit , function (e) {
e.preventDefault();
$.ajax({
type:  post ,
 url:  yourpage.php ,
 data: $( #form ).serialize(),
 success: function(){
        alert( success );
          },
});
 });
 }); 
});

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/39530522/ajax-jquery-cross-domain-form-submission

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils