이 모든 페이지를 새로 고치지 않고이 양식을 자동으로 제출하려면 어떻게합니까?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>JQuery Form Example</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script><!--need at least one instance of jquery-->
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script><!--ajax to use with jquery-->
<script type="text/javascript">
$(document).ready(function(){//when the document has loaded
$("#myform").validate({//Q: what is validate?, myform gets validated
debug: false,
rules: {
name: "required",//name and email are the only things passed
email: {
required: true,
email: true//I guess this defines the input as an email
}
},
messages: {//at what point is this message displayed?
name: "Please let us know who you are.",
email: "A valid email will help us get in touch with you.",
},
submitHandler: function(form) {//submit the form
// do other stuff for a valid form
$.post('process.php', $("#myform").serialize(), function(data) {//Q:what is serialization? myform gets serialized and assigned an action
$('#results').html(data);//what is this?
});
}
});
});
window.onload=function()
{
}
</script>
<style>
label.error { width: 250px; display: inline; color: red;}
</style>
</head>
<body>
<form name="myform" id="myform" action="" method="POST">
<!-- The Name form field -->
<label for="name" id="name_label">Name</label>
<input type="text" name="name" id="name" size="30" value="Charlie"/>
<br>
<!-- The Email form field -->
<label for="email" id="email_label">Email</label>
<input type="text" name="email" id="email" size="30" value="[email protected]"/>
<br>
<!-- The Submit button -->
<input type="submit" name="submit" value="Submit">
</form>
<!-- We will output the results from process.php here -->
<div id="results"><div>
</body>
</html>
<!--ok, so I want to first try some stuff out to get a feel for how the form works-->
<!--upload the form to the site somewhere-->
<!--access and play around with it-->
<!--then figure out how to submit to multiple php forms-->
그래서 나는 JQuery와 및 Ajax를 사용하고 PHP 파일에, 나는 자동으로 양식을 제출해야합니다.
나는 document.myform.submit과 같은 것을 사용하려고 시도했지만 작동하지 않는 것 같습니다. 그것은 아약스를 사용하지 않을 때 작동하지만, 그 페이지는 PHP 파일의 대상으로 새로 고치게됩니다.
저는 일부 구문이 누락되었다고 생각합니다. 검색을 수행하여 다음과 같은 몇 가지 스레드를 찾았습니다. Ajax auto form submit
그러나 저는 취미 애호가이기 때문에 더 이상 말하고 있지 않습니다. 나는 다른 사람들에게 내 코드를 수정하는 일을 맡기지 않을 것이지만, 나는 그 변화가 사소하다는 것을 확신하고 있으며, 이것을 알아 내려고 노력하고있다. 도움이되는 사람에게 많은 감사를드립니다! 방향을 자세히 설명해 주시면 코드 자체에서 직접 수정 사항을 제공 할 수 있다면 좋을 것입니다.
편집 : 내 의견에 너무 열심히 웃지 마세요. 코드를 이해하고 (많이 검색 한 후) 훨씬 좋았습니다. 몇 시간 전부터 수정되었습니다.
double edit : 여기 process.php라는 샘플 PHP 스크립트가 있습니다. 자동 제출이 제대로 작동하는지 보려면 편집해야합니다. 위에서 언급했듯이, 당신은 MySQL 데이터베이스로 이것을 할 수 있습니다.
print "Form submitted successfully: <br>Your name is <b>".$_POST['name']."</b> and your email is <b>".$_POST['email']."</b><br>";
와우 감사합니다. 모든 답변이 작동한다고 생각하고 jquery 양식 플러그인을 좋아합니다. 나는 그것을 일찍 사용하고 있었다. 이 답변은 가장 간결하지만 직렬화에 대해 좀 더 자세히 가르쳐 줬습니다. 나는 폼이 작동했다는 것을 알았고, 자동 제출을하지 않았고, 다음 번에이 질문을 할 때 좀 더 구체적이고 덜 피곤하도록 노력할 것입니다. 감사! – obesechicken13