I have an Ajax script that relays form information to PHP upon user submission. The data is inserted into the table and then returns a string back to Ajax. For some reason, instead of getting the string I am getting the full HTML code of the page. How do I go about getting the string instead of the HTML code?
HTML
<form id='orderForm' action='' method='post'>
<h2>Choose your pizza size</h2><hr>
<select name='size'>
<option value='' disabled selected>Choose a size</option>
<option value='small'>Small</option>
<option value='medium'>Medium</option>
<option value='large'>Large</option></select>
<h2>Choose your toppings</h2><hr><label><input type='checkbox' name='check_list[]' value='beef'>Beef</label>
<label><input type='checkbox' name='check_list[]' value='pepperoni'>Pepperoni</label>
<label><input type='checkbox' name='check_list[]' value='chicken'>Chicken</label>
<label><input type='checkbox' name='check_list[]' value='sausage'>Sausage</label>
<h2>Enter your details</h2><hr><input type='text' name='name' placeholder='Full Name'>
<input type='email' name='email' placeholder='Email'>
<input type='text' name='phone' placeholder='Phone number'>
<input type='text' name='address' placeholder='Address'>
<input id='zip' type='text' name='zip' placeholder='Zip Code'>
<p id='message'></p>
<input id='submitBtn' type='submit' name='submitBtn' value='Place Order'>
</form>
AJAX
$.ajax({
type: 'post',
url: 'validation.php',
data: $("#orderForm").serialize(),
datatype: "html",
success: function(data){
window.location = data;
}
})
PHP
if (isset($_POST["email"])){
$orderId = time() + mt_rand(1,10);
$toppings = implode(', ', $_POST['check_list']);
$result = $db->prepare("INSERT INTO orders (order_id, type, pizza_type, size, toppings, name, address, email, number) VALUES (?, ?,?,?,?,?,?,?,?)");
$result->bind_param("sssssssss", $orderId, $_GET['type'], $_GET['order'], $_POST['size'], $toppings, $_POST['name'], $_POST['address'], $_POST['email'], $_POST['phone']);
$result->execute();
$db->close();
echo "?success=true&orderid=' . $orderId . '&toppings=' . $toppings";
}