Sen JQuery denemelisiniz. Ben göndermek ve bu formu olduğunu varsayarak, aşağıdaki şekilde PHP JS alırsınız.
<div id="form">
<input type="text" id="email" /><br />
<button id="submit">Submit</button>
</div>
<div id="response">
</div> <!-- load jquery -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript" > </script>
// put this in script type="text/javascript" tags
$(document).ready(function(){
var emailValue;
$("#submit").click(function(){
// when the user clicks the submit button
// get the value of email and put it in the variable we made above
emailValue=$("#email").val();
/* am going to send a post variable called "email"
* with the value of "emailValue" to a script called receiver.php
*/
$.post('receiver.php',{email:emailValue},function(e){
// "e" is variable that contains the echoed string
// check if it's true or false
if(e=="true")
alert ("valid email");
else
alert("invalid email");
});
});
});
receiver.php
$email=$_POST['email'];
// checkMail is a fictional function that returns a bool
$valid=checkMail($email);
if($valid)
{
// email is valid
echo "true";
}else{
// email is invalid
echo "false";
}
Note: Eğer $.get
yerine $.post
, bu biraz daha hızlı kullanımı gereken PHP komut dosyası veri gönderme değilse.
Ayrıca JavaScript değişkeni e
kullanmak ve bu gibi formda response
bölümü içeriğini yükleyebilirsiniz
$("#response").html(e);
Eğer Coder gibi JQuery'nın load()
fonksiyonu aşağıda bahseder kullanıldığı gibi, bu aynı şeyi başarmak istiyorum.