0

According to jquery API this is the wat of sending value asigned to a name with ajax

.data( key, value )

Problem is my values are already in php variables. how can i send them using ajax?

this problem is relate to this question i asked yesterday. Still couldn't find a way to send php variables to another php page when a button is clocked. sad that jQuery API Documentation doesn't have examples.

2 Answers 2

1

You have two php....let say page.php and ajax.php. If you call ajax.php from ajax in page.php you must write variables from php to javascript with something like

var data1 = <?= $data1 ?>;
var data2 = <?= $data2 ?>;

and then add these variables to ajax call.

Best regards, nele

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

Comments

1
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<script type="text/javascript">

var ajax_value1 = $("#ajax_value1").val();

var ajax_value2 = $("#ajax_value2").val();

 $.ajax({

     type: "POST",

     url: 'sample.php?ajax_value1='+value1+'&value2='+ajax_value2,

     //Specify the datatype of response if necessary

     data: $("#your_form_id").serialize(),

     success: function(data){

     }

});

</script>


<!-- Set your ajax value in html input fields -->

<input type="text"  name="ajax_value1" id="ajax_value1" value="<?php echo $ajax_value1;?>" > 

<input type="text"  name="ajax_value2" id="ajax_value2" value="<?php echo $ajax_value2;?>" >

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.