1
<script type="text/javascript">
$(function() {

$("#epdate").bind("change", function() {
 $.ajax({
     type: "GET", 
     url: "change6-emp.php",
     data: "epdate="+$("#epdate").val(),
     success: function(html) {
         $("#output").html(html);
     }
 });
});


});
</script>

i have this code and i want to add another variable inside ajax script adding another

data: "empname="+$("#empname").val(),

dopesnt work i hope someone would help me. thank you and how can i call a postname or make a postname into session an call it into another php page?

1

1 Answer 1

1

Actually, there are multiple ways, either separate them using a & character.

<script type="text/javascript">
$(function() {

$("#epdate").bind("change", function() {
 $.ajax({
     type: "GET", 
     url: "change6-emp.php",
     data: "epdate=" + $("#epdate").val() + "&empname="+$("#empname").val(),
     success: function(html) {
         $("#output").html(html);
     }
 });
});


});
</script>

Or alternatively, you can use an object which holds the name-value pair.

<script type="text/javascript">
$(function() {

$("#epdate").bind("change", function() {
 $.ajax({
     type: "GET", 
     url: "change6-emp.php",
     data: { epdate : $("#epdate").val(), empname : $("#empname").val() },
     success: function(html) {
         $("#output").html(html);
     }
 });
});


});
</script>

UPDATE 1: You can also pass it as an array in the following format,

data : [{
    name : 'epdate',
    value : $("#epdate").val()
  }, {
    name : 'empname',
    value : $("#empname").val()
  }],

UPDATE 2: There is build in functions in jQuery to do the same, use [serialize()][] or serializeArray() method for that. You can apply it on a form element or input elements and which generates based on the input elements name attribute.

data : $('#epdate,#empname').serialize(),
// or
data : $('#epdate,#empname').serializeArray()

,

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.