Question

here's a stupid question. I've got this associative array that I need to POST via ajax request:

var ajax_data = "{email: "email", pass: "password"}";

now in my php code I'm supposed to get this data via $_POST[something], right? my question is what's the name of the POST request?? and how can I change it??? tanx

Was it helpful?

Solution

I suggest you look jquery doc for ajax

here is a sample usage of ajax method:

$.ajax({
  type: "POST", // type POST or GET
  url: "some.php", // php file that data send to
  data: { name: "John", location: "Boston" } // here is your data in json format
})
  .done(function( msg ) {
    alert( "Data Saved: " + msg );
  });

data format is really simple, it's format just like this

{ key: 'value', anotherKey: 'anotherValue', ... }

and you can access data in php like this

$firstData = $_POST['key'];          // this variable contains 'value'
$secondData = $_POST['anotherKey'];  // this variable contains 'anotherValue' 

anything your write instead of key and anotherKey is key of your variable in $_POST and value & anotherValue are those values

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top