这应该很容易,我几乎不能抓住问题近一个小时,所以也许我错过了什么。
我想创建一个没有“谢谢”页面的自适应联系表单,所以我使用的是ajax。
我写了所有的代码, 这是我对我的控制台的反应:
Uncaught RangeError: Maximum call stack size exceeded
继续无限运行。
这是我的表格:
<div id="contactform" style="position: relative; top: 180px; left: 50px;">
<table width="600px" class="contactform" >
<tr>
<td colspan="2"> Full Name: <br/> </td>
<td colspan="2"> <input type="text" id="fullname" /> </td>
</tr>
<tr>
<td colspan="2"> Phone Number: </td>
<td colspan="2"> <input type="text" id="telephone"/> </td>
</tr>
<tr>
<td colspan="2"> Email Adress: </td>
<td colspan="2"> <input type="text" id="email"/> </td>
</tr>
<tr>
<td colspan="2"> Subject: </td>
<td colspan="2"> <input type="text" id="subject" /> </td>
</tr>
<tr>
<td colspan="2"> Content: </td>
<td colspan="2"> <textarea rows="5" cols="50" id="text"> </textarea> </td>
</tr>
<tr>
<td colspan="2"> </td>
<td colspan="2"> <input type="button" class="link" value="Send" id="sendBtn" /> </td>
</tr>
</table>
</div>
这是我在.js文件中的ajax代码部分:
$('#sendBtn').click(function(){
//get info
console.log("dude!");
var fullname = $("#fullname").val();
var telephone = $("#telephone").val();
var email = $("#email").val();
var subject = $("#subject").val();
var text = $("#text").val();
//send info to php
$.ajax({
beforeSend: function() {
// $("#spin").html(spiner);
},
url: 'http://www.example.com/MYtest/contact.php',
type: "POST",
data: ({ "fullname": fullname, "telephone": telephone, "email": email, "subject": subject, "text": text }),
success: function (results){
// $("#spin").hide(spiner);
console.log(email);
//hide table
$('#contactform').hide('slow', function() {
// Use arguments.callee so we don't need a named function
$('#contactform').hide( "slow", arguments.callee );
});
//show textboxes
$('#aboutSuccess').show("slow");
}
});
});
这是我的content.php:
if(isset($_POST['email'])) {
$email_to = "meEmail@example.com";
$email_subject = "You have a new email from example.com";
$fullname = $_POST['fullname'];
$telephone = $_POST['telephone'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$text = $_POST['text'];
$message = "Full Name: ". $fullname ."\n Telephone: ". $telephone ."\n Email: ". $email ."\n Subject: ". $subject ."\n \n Message: \n". $text;
mail($email_to, $email_subject, $message);
}
答案 0 :(得分:1)
您正在函数内部调用arguments.callee
。这就是导致循环的原因。
$('#contactform').hide('slow', function() {
// Use arguments.callee so we don't need a named function
$('#contactform').hide( "slow", arguments.callee );
});
我不知道你要用这个代码做什么,也许是剩下的。尝试将其替换为:
$('#contactform').hide('slow');