I contacted GoDaddy about this, in case it is something on their end, but they couldn't really help. I'm trying to send a contact form via JSON in a xmlhttprequest, and I'm sending it via a POST request. Unfortunately, and this is something that wasn't happening on another hosting service, it is being received as a get request. Here is my js code, and what Chrome is displaying after sending it:
code:
function SendJson(values, type){
var xhr = new XMLHttpRequest();
var url = 'http://www.klemequestrianestates.com/processes/mail_form.php';
var data = JSON.stringify(values);
console.log(data);
xhr.open('POST', url);
xhr.setRequestHeader('Form-Type', type);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(data);
xhr.onreadystatechange = function(){
if(xhr.readyState === 4){
//success confirmation
}
};
}
Where Values is a js object, and type is either 'sell' or 'buy' (the form has 2 different types of clients that might use it, and sellers and buyers have different fields.
Here is the PHP file:
<?php
header('Access-Control-Allow-Headers: *');
header("Access-Control-Allow-Methods: POST, GET");
$data_type = $_SERVER['HTTP_FORM_TYPE'];
$raw_JSON = file_get_contents('php://input');
$converted_JSON = json_decode($raw_JSON);
echo var_dump($converted_JSON);
$type = $_SERVER['REQUEST_METHOD'];
echo var_dump($type);
if($data_type === 'sell'){
$first_name = $converted_JSON->div_00;
$last_name = $converted_JSON->div_01;
$phone_num = $converted_JSON->div_02;
$email = $converted_JSON->div_03;
$street = $converted_JSON->div_04;
$city = $converted_JSON->div_05;
$state = $converted_JSON->div_06;
$zip = $converted_JSON->div_07;
$option = $converted_JSON->div_08;
$message = $converted_JSON->div_09;
$to = 'contact@joshualyness.com';
$subject = $first_name.' '.$last_name.', '.$option;
$body = 'From: '.$email.PHP_EOL.PHP_EOL.'Phone Number: '.$phone_num.PHP_EOL.PHP_EOL.'Address: '. $street.PHP_EOL.$city.PHP_EOL.$state.PHP_EOL.$zip.PHP_EOL.PHP_EOL.'Message: '.$details;
mail($to, $subject, $body);
}
Here is the var dump contents:
Any ideas why this is happening? If you need any more details, drop a comment and I'll see what I can do. I know it's a bit of a weird question, I wouldn't be bothering the community if I didn't have any other ideas. Thanks.