coiso
coiso

Reputation: 7479

Undefined Index in a jquery AJAX send and receive data request

test.php

$aaa = $_POST['aaa'];

echo $aaa;

Javascript Code

$.ajax({

url: 'ajax/test.php', 
data: { aaa: 'names_' },
success: function(data) {
alert("Data Loaded: " + data); 
            }
      });

The alert response is:

NOTICE: Undefined Index: aaa  

What might cause this?

Upvotes: 1

Views: 1834

Answers (3)

SelaYou
SelaYou

Reputation: 21

You should claim the submit method

$.ajax({
  type:"POST",
  ...
});

Upvotes: 1

Marian Zburlea
Marian Zburlea

Reputation: 9427

Add to the ajax object the type attribute:

$.ajax({
  url: 'ajax/test.php', 
  type:'post',
  data: { aaa: 'names_' },
  success: function(data) {
    alert("Data Loaded: " + data); 
  }
});

Upvotes: 4

Nicolas-Verley
Nicolas-Verley

Reputation: 88

data: {'aaa':'names_'} I think will be better

Upvotes: -1

Related Questions