我有一個使用jquery ajax()提交表單數據的聯繫人。它適用於xampp,但在服務器上,應該發送到php文件的表單數據變爲空白。什麼都沒有被髮送到外部文件ajax()在提交時丟失了表單數據
$(document).ready(function(){
$("input#regbut").click(function(){
var edin = $("input[name^='name']").val();
var mailer = $("input[name^='email']").val();
var dept = $("input:radio[name^='direct']:checked").val();
var hint = $("input[name^='subject']").val();
var bodied = $("textarea[name^='message']").val();
var seri = "name=" + edin + "&email=" + mailer + "&direct=" + dept + "&subject=" + hint + "&message=" + bodied;
$("span#war").fadeIn(function(){
$("span#war").css("display", "block");
});
$("#warn").html('');
if(edin ==''){
$("#warn").html('You did not tell us your name');
}else if(mailer == ''){
$("#warn").html('Your email is required');
}else if(hint == ''){
$("#warn").html('Subject is required');
}else if(bodied == ''){
$("#warn").html('You did not tell us what the problem is');
}else{
$.ajax({
type: "GET",
url: "contactpro.php",
data: seri,
error: function(){
$("#warn").html("Sorry! an error occurred");
},
success: function(repo){
$("#warn").html(repo);
alert(repo);
}
});
}
return false;
});
});
<form method="post" id="cotact">
<table width="80%" border="0" cellspacing="3" cellpadding="1">
<tr>
<td></td>
<td id="warn" style="color:#FF0000;"><h3 style="color:#0099FF;"><span id="war" style="display:none;">Sending...</span></h3></td>
</tr>
<tr>
<td>Name</td>
<td><label>
<input name="name" type="text" class="input" id="sign_up" />
</label></td>
</tr>
<tr>
<td>Email </td>
<td><label>
<input name="email" type="text" class="input" id="sign_up" />
</label></td>
</tr>
<tr>
<td>Direct to</td>
<td><p>
<label>
<input name="direct" type="radio" id="direct_0" value="1" checked="checked" />
General</label>
/enquiry<br />
<label>
<input type="radio" name="direct" value="2" id="direct_1" />
Advertising</label>
<br />
<label>
<input type="radio" name="direct" value="3" id="direct_2" />
Reports</label>
<br />
<label>
<input type="radio" name="direct" value="4" id="direct_3" />
Suggestions</label>
<br />
</p></td>
</tr>
<tr>
<td>Subject</td>
<td><label>
<input name="subject" type="text" class="input" id="sign_up" />
</label></td>
</tr>
<tr>
<td>Message</td>
<td><label>
<textarea name="message" cols="45" rows="5" class="input" id="sign_up" style="height:100px;"></textarea>
</label></td>
</tr>
<tr>
<td> </td>
<td><label>
<input type="submit" name="submit" id="regbut" value="Submit" />
</label></td>
</tr>
</table>
</form></td>
</tr>
<tr>
<td colspan="2" align="center"></td>
</tr>
</table>
相對路徑是一樣的嗎? – Wold 2014-10-04 04:59:09
將'type:「GET」'更改爲'type:「POST」'和'data:「seri」'更改爲'data:「postDATA」'。另外,表單方法也應該是「POST」。 – mijopabe 2014-10-04 05:01:00
爲什麼你用GET發送比較大量的信息?此外,構建像'seri =「name =」+ edin +「&email =」+ mailer +「&direct =」'這樣的數據是一個糟糕的主意 - 如果其中一個變量具有&,那該怎麼辦?你應該逃避數據或讓jQuery爲你做。 – Cheery 2014-10-04 05:01:18