Use jQuery to add a connection to a field


Im using PHP to list records.

Each record has a button.

Once the user clicks a button I need to add a new user with a connection to the record that the user clicked.

Right now, Im using this:  

$('#button').click(function(event) {
	// replace XXX with your application ID
	url: "",
	type: "POST",
	headers: {"X-Knack-Application-Id": "myID", "X-Knack-REST-API-Key": "myKey"},
	data: JSON.stringify({
	field_37 : ""
	success: function(response) { 
	alert('Record Added!');
});		});


The user gets created but the email field (field_37) is empty.

So I have two questions:

What am I doing wrong to enter the email?

How can I enter a new connection to the record the user clicked?

Thank you.

One extra step, which I will ask in another topic, is how to use the logged in user to add the connection to his profile. 

For anyone wanting to add a user with values using ajax, the basic code is this:

//execute this when user clicks the button
	$('.button').click(function(event) {
// use the following data.
var data = {
	field_37 : { 
		'email' : '',	//new user email to be inserted in field 37
		'label' : 'example'
	field_41 : [55a1b550b2847881712431fe] //this is the id of the record you want to add to the new user inside of connection field_41

// insert the record
// this uses the PAGE API access to use an existing form to insert the record.

// replace XXX with your application ID
url: "",
type: "POST",
headers: {"X-Knack-Application-Id": "xxx", "X-Knack-REST-API-Key": "xxx"},
data: data,
success: function(response) { 
alert('Record Added!');

});&nbsp;</pre><p>&nbsp; &nbsp;</p>

Hello Nicolas! 

Thank you. You saved me tons of extra time.

Hi Mauricio,

Knack is expecting an Object for the email field -- take a look here: