In: Computer Science
How can I get res_ticket using php getstring?
var post_data = "res_id=RYSEZ21786" +
"&res_ticket=res8azjcfLQTHNU2mVtG" +
"&pan=" + encodeURIComponent(document.getElementById('pan').value) +
"&pan_mm=" + encodeURIComponent(document.getElementById('exp_month').value) +
"&pan_yy=" + encodeURIComponent(document.getElementById('exp_year').value) +
"&cardholder=" + encodeURIComponent(document.getElementById('cardholder').value) +
avs_details +
cvd_details +
"&doTransaction=res_add";
HI,
I think you are asking to sendjavascript variable to php script to get the string "res_ticket=res8azjcfLQTHNU2mVtG"
There is two way to do this:
1. You can split the post_data varialb estring in javascript and can set it in html hidden feild from JS function and with you can get that res_ticket at php side by method $GET["res_ticket"]
like below
<script type="text/javascript">
//pass your post_data variable in this javascript function
function getstring(post_data) {
var arr = str.split("&");
document.getElementById("res_ticket").value = arr[0];
}
</script>
<form name="myform" action="" method="POST">
<input type="hidden" name="res_ticket" id="res_ticket" />
</form>
<?php
$res_ticket = $_POST['res_ticket']; // or by $_GET["res_ticket"]
echo $query;
?>
Another way if you can set your javascript post_data variable to php file by above method and can parse string by php explode metthod like below
// string which can be long like your given string saperated by "&"
$post_data = "res_id=RYSEZ21786&res_ticket=res8azjcfLQTHNU2mVtG" ;
// pass delimiter and string to explode function.it will convert array of string
$post_data_arr = explode('&', $post_data);
// view result using var_dump..it will get the "res_ticket" string from array
var_dump($post_data_arr[1]);
Above are two way to sent javascript variable to php script..
Feel free to ask any question if you might have by comment box.
Thanks