0v3k Shi3ld3r 0v3k Shi3ld3r - 4 months ago 11
Javascript Question

Pass $_GET to Script (AJAX)

I would like to pass $recptid = $_GET['id']; To the following

<div id="result"></div>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#name').focus();
$('#name').keypress(function(event) {
var key = (event.keyCode ? event.keyCode : event.which);
if (key == 13) {
var info = $('#name').val();
$.ajax({
method: "POST",

//need to pass my get variable
url: "message_action.php",
data: {name: info},
success: function(status) {
$('#result').append(status);
$('#name').val('');
}
});
};
});
});
</script>


Which then executes message_action.php query's as at the moment my error is Undefined variable: recptid . As my query cannot access it due to been in separate file for AJAX

How can I pass $recptid to message_action.php please?

Answer

in your data: {name: info}, just put the thing too.. data: {name: info, recptid: '<?php echo $_GET["id"]; ?>'}, then in message_action.php just use $_POST['recptid']; (use post since your AJAX Call uses POST method)

Comments