How to send multiple parameters to php using ajax -


here trying send multiple variable values php page through ajax.

here calling javascript function values form , submit values ajax. in javascript getting multiple values form. want pass these values php page.

how can achieve that?

here have done.

function sendinvite(){       var from_name = document.getelementbyid('invite_username').value;     var name_string = 'invitename='+ from_name;      var email = document.getelementbyid('friendemail').value;     var mail_string = 'friendemail='+ email;          var product_name = document.getelementbyid('invite_productname').value;     var product_string = 'invite-product-name='+ product_name;      var product_link = document.getelementbyid('invite_url').value;     var link_string = 'invite-url='+ product_link  ;         $.ajax({         type : "post",         url : "legoland.php",         data: name_string,mail_string,         cache:false,         success : function(html){             $('.mail-message').html(html);         }     }); } 

html:

<form name="invite-form">                   <div class="col-md-4 col-lg-4">          <label class="control-label" for="friend">enter email address</label>                        <input type="email" class="form-control" name="friendemail" id="friendemail" placeholder="sam@uncle.com" required><br>                                          <?php           echo '<input type="hidden" id="invite_username" name="invitename" value="' . $_session["user_name"] . '">' ;                           echo '<input type="hidden" id="invite_url" name="invite-url" value="'.$_server['request_uri'].'">';          echo '<input type="hidden" id="invite_productname" class="invite-product" name="invite-product-name">';          ?>          <input type="button" name="submit" onclick="return sendinvite();" value="invite" class="btn btn-primary">      </div>             </form> 

php:

 <?php      $name = $_post['invitename'];     $mail = $_post['friendemail'];       $product_name = $_post['invite-product-name'];       $product_link = $_post['invite-url'];         echo $name;     echo $mail;     echo $product_name;     echo $product_link; ?> 

from manual:

data type: plainobject or string or array data sent server. converted query string, if not string. it's appended url get-requests. see processdata option prevent automatic processing. object must key/value pairs. if value array, jquery serializes multiple values same key based on value of traditional setting (described below).

so easiest change data

data: { invitename: from_name, friendemail: email } 

you can assign values directly data variable

 data: {      invitename: document.getelementbyid('invite_username').value,      friendemail: document.getelementbyid('friendemail').value   } 

etc.


Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -