I am trying to make a post
request to my api
which saves the data that I send through my request. I have tried all the solutions that I found here on SO but none worked.
This is how I am sending the request through ajax
:
var data={
apiname: 'register', first_name: fname, last_name: lname, email_address: email,
acc_pass: pass, coach_phone: phone, coach_dob: dob, profile_picture: myFile,
coach_address: address, coach_state: state, coach_city: city, zip_code: zip, coach_bio: about,
teaching_locations: teaching, playing_exp: playing_exp, teaching_exp: teaching_exp,
private_lesson_rate: private_rate, group_lesson_rate: group_rate, certification: certifications,
any_crime: 'No', us_citizen: 'Yes', allowed_contract_work: 'Yes', agree_terms: 'Yes',
virtual_session: sessions
};
$.ajax({
type: "POST",
url: "my-url/signup_api.php",
processData: false,
contentType: "application/x-www-form-urlencoded",
dataType: 'json',
data: data,
success: function (data2) {
if (data2.status == '200') {
alert(data2.message);
}
else {
showError(data2.message, 3000);
}
},
error: function (jqXHR, exception) {
alert(exception);
}
});
I don't want to send the data in a json
way like json.stringify
. The variables (fname, lname etc) are the input fields of my form and I am getting the values like this:
var fname = $("#first_name").val();
and same for all the other variables. And on my php
side, I am trying to access the data like this:
if($_POST['apiname']=="register"){
//do stuff
}
But my code never gets inside this if
statement. Been stuck on this since last 2 days now.