Not able to POST Variable to Another Page (PHP, Javascript, AJAX) -
i have while loop (inside "searchvessel.php") display content of query , have button "upgrade" each record of query.
`while($fetch = $read->fetch_array()) { ?> <tr> <td id="1" style="display:none;"><?php echo $fetch['vesselid']?></td> <td id="2"><?php echo $fetch['vesselname']?></td> <td><input type="submit" class="button" name=<?php echo $fetch['vesselid']; ?> value="upgrade"/></td> </tr>`
this "upgrade" button when click call javascript code use value inside tag name pass page using ajax.
<script type = "text/javascript"> $('.button').click(function(){ alert($(this).attr('name')); $.ajax({ type: "post", data: { name: $(this).attr('name') }, url: "vesselrecord.php", datatype: "json", async: true, beforesend: function(){ $(".ajaxtest").text("trying upgrade..."); }, complete: function(){ window.location.href = "vesselrecord.php"; }, success: function(data) { $(".ajaxtest").text(data.a); if (data.b == "true") { location.reload(); } } }); }); </script>
- i able prompt/alert value of vessel identification using "alert($(this).attr('name'));"
- move/transfer "vesselrecord.php
- but inside "vesselrecord.php" there no value in $_post['name']. looks there issue on ajax code. can guide me on this? tia.
below code inside "vesselrecord.php"
if($_server['request_method'] == 'post') { $vessel_id = strip_tags($_post['name']); }
when change location of window, make $get request not $post, why not getting value $_post['name']
.
you can change location from-
window.location.href = "vesselrecord.php"
to-
window.location.href = "vesselrecord.php?myquerystringdata=" + $(this).attr("name");
and on php file can write code value query string.
Comments
Post a Comment