Reputation: 3111
using ajax code:
$.ajaxSetup({
url: "last-id-test.php",
type: "POST",
});
$.ajax({
data: {theinfo: 'forminfo'},
success: function(data) {alert(data)},
error: function (XMLHttpRequest, textStatus, errorThrown){alert('Error submitting request.')}
});
and then simple php of last-id-test.php:
$showme = $_GET['theinfo'];
I always get the error 'undefined index - theinfo'...
I cant see my mistake?
Upvotes: 0
Views: 75
Reputation: 376
As mentioned in the comments GET and POST methods result in data being passed in to different global variables in PHP -- GET == $_GET POST == $_POST
So in this case try in your php:
$showme = $_POST['theinfo'];
Useful for debugging is
print_r($_GET); // or $_POST or $_COOKIE
More info on these global variables: http://www.php.net/manual/en/reserved.variables.php
Upvotes: 1
Reputation: 3543
Try following:
$.ajaxSetup({
url: "last-id-test.php",
type: "POST",
});
$.ajax({
data: {'theinfo': 'forminfo'},
success: function(data) {alert(data)},
error: function (XMLHttpRequest, textStatus, errorThrown){alert('Error submitting request.')}
});
Note that the single quotes are used around the variable name.
Now you need to access the passing variable using POST array since your type is set as POST
$showme = $_POST['theinfo'];
Upvotes: 1