Can I use $.ajax() to send POST to PHP file on other domain? A have a error message in $.ajax(). In Chrome or Firefox - email send. In IE - email is not send.
This is HTML file
<form name="order" method="post"action="http://www.site.ru/images/stories/controller.php">
<label>1. Mark*:</label>
<select name="mark" class="inputbox">
<option ="selected"></option>
<option>Audi</option>
<option>BMW</option>
</select>
<label>2. Model*:</label>
<input type="text" name="model" size="30" class="inputbox"/>
<label>3. Year*:</label>
<select name="year" class="inputbox">
<option ="selected"></option>
<option>2011</option>
<option>2010</option>
</select>
<label>4. Value, l*:</label>
<input type="text" name="value" class="inputbox" size="30"/>
<label>5. Transmission*:</label>
<select name="transmission" class="inputbox">
<option ="selected"></option>
<option>Manual</option>
<option>Automatic</option>
</select>
<label>6. VIN:</label>
<input type="text" name="vin" size="30" value="" class="inputbox" maxlength="17" />
<label>7. E-mail*:</label>
<input type="text" name="email" size="30" class="inputbox" />
<label>Note*:</label>
<textarea cols="50" rows="5" name="text" id="contact_text" class="inputbox"/</textarea>
<input type="button" value="Send" onclick="valid();"></input>
</form>
<script src="http://admin.abcp.ru/common.jscripts/jquery/jquery-1.6.2.min.js"></script>
<script language="JavaScript" type="text/javascript">
function sendEmail(mark, model, year, value, transmission, vin, email, text){
$.ajax({
url: "http://www.site.ru/images/stories/controller.php",
type : "POST",
data : {
mark : mark,
model : model,
year : year,
value : value,
transmission : transmission,
vin : vin,
email : email,
text : text
},
success: function(){
alert('Success.');
},
error : function (){
alert('Error.');
}
});
}
</script>
<script language="JavaScript" type="text/javascript">
function valid(){
if (document.order.mark.value == ""){
alert("Mark is empty.");
document.order.mark.focus(true);
return false;
}
if (document.order.model.value == ""){
alert("Model is empty.");
document.order.model.focus(true);
return false;
}
if (document.order.year.value == ""){
alert("Year is empty.");
document.order.year.focus(true);
return false;
}
if (document.order.value.value == ""){
alert("Value is empty.");
document.order.value.focus(true);
return false;
}
if (document.order.transmission.value == ""){
alert("Transmission is empty.");
document.order.transmission.focus(true);
return false;
}
if (document.order.email.value == ""){
alert("E-mail is empty.");
document.order.email.focus(true);
return false;
}
if (document.order.text.value == ""){
alert("Text is empty.");
document.order.text.focus(true);
return false;
}
sendEmail(document.order.mark.text,
document.order.model.text,
document.order.year.text,
document.order.value.text,
document.order.transmission.text,
document.order.vin.text,
document.order.email.text,
document.order.text.text);
}
</script>
This is PHP file controller.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Обратная связь</title>
</head>
<body>
<?php
$from = $email;
$to = "[email protected]";
$subject = "PINAZA.RU - Запрос по $mark";
$message = "Марка автомобиля: $mark \nМодель автомобиля: $model \nГод выпуска: $year \nОбъем двигателя, л: $value \nТип КПП: $transmission \nVIN-код: $vin \nНеобходимые детали: $text";
$headers = "Content-type: text/plain; charset = utf-8";
mail("$to", "$subject", "$message", "from: ".$from."\r\n"."$headers");
?>
</body>
</html>