-1

i am trying to post a javascript variable posY to a php file. i get an error Notice: Undefined index: data in C:\xampp\htdocs\Heads_in_the_clouds\submitposY.php

posY is defined in the javascriptn so thats not the problem

heres the code

$.ajax({
type: "POST",                                     
url: "submitposY.php",                                             
data : { data :posY }
});

and the php on submitposY.php is

echo $_POST['data'];
Imad_bush
  • 3
  • 1
  • 3
  • 1
    Replace { data :posY } with { data :42 }, just to be sure you send a real value. – farvilain Jan 04 '14 at 20:13
  • possible duplicate of [How to debug a PHP file that is being called by AJAX?](http://stackoverflow.com/questions/1620784/how-to-debug-a-php-file-that-is-being-called-by-ajax) or [PHP: “Notice: Undefined variable” and “Notice: Undefined index”](http://stackoverflow.com/q/4261133/367456) – hakre Jan 12 '14 at 10:06

1 Answers1

-1

The method should be "post", not the type. Hence:

$.ajax({
method: "post",                                     
url: "submitposY.php",                                             
data : { data :posY }
});
amir-f
  • 711
  • 1
  • 8
  • 17