http://docs.jquery.com/Ajax
http://docs.jquery.com/Ajax/jQuery.get#urldatacallbacktype
Tror løsningen vil være cirkus lige nedestående:
<script>function submit() {
$.get("test.php", { name: document.getElementById('name').value, time: document.getElementById('email').value } );
}
</script>
<form onsubmit="submit(); return false;">
<input id="name" value="navn" />
<input id="email" value="email" />
</form>
Hvordan skal jeg så fange email og navn i test.php? GET eller POST?
Dén der kode kan du ikke bruge.
Brug den her i stedet. Du kan bare tilpasse den til dit behov
:
- function buttonAvaible(s) {
- if (s==true) {
- document.getElementById('sendmail').disabled=false;
- document.getElementById('sendmail').value='Add comment';
- }
- if (s==false) {
- document.getElementById('sendmail').disabled=true;
- document.getElementById('sendmail').value='Plase wait..';
- }
- }
- var xmlhttp;
- if (window.XMLHttpRequest) {
- xmlhttp=new XMLHttpRequest();
- } else if (window.ActiveXObject) {
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- } else {
- alert("Your browser is outdated. Get Firefox, Chrome or Opera instead!");
- }
- function sendMail() {
- xmlhttp.onreadystatechange=function() {
- if(xmlhttp.readyState==4) {
- document.getElementById('added').innerHTML=xmlhttp.responseText;
- if (document.getElementById('added').innerHTML=='You need to fill out all the text fields!.') buttonAvaible(true);
- } else {
- document.getElementById('sendmail').value='Email sent!';
- }
- }
- var subject = document.mail.subject.value;
- var content = document.mail.content.value;
- var url = 'sendmail.php?subject='+subject+'&content='+content;
- xmlhttp.open("GET",url,true);
- xmlhttp.send(null);
- }
- <form name="mail" method="post">
- Subject: <input type="text" name="subject"><br/>
- Content:<br/><textarea style="width:350px; height:120px;" name="content"></textarea><br/>
- <input type="button" id="sendmail" onclick="sendMail();buttonAvaible(false)" value="Send mail"><span id="added"><noscript>The email system is based on AJAX and you do therefore need a browser with JavaScript support to post use this mail form</noscript></span>
- </form>
PHP filen skal hedde sendmail.php
- if ($_GET[subject]!="" && $_GET[content]!="") {
- $time = time();
- mail("MODTAGER@EMAIL.COM", scan($_GET[subject]), scan($_GET[content]));
- echo "The email was sent!";
- } else { ?>You need to fill out all the text fields!.<?php } ?>
Indlæg senest redigeret d. 16.08.2009 17:55 af Bruger #10113