hvad du kan gøre er at sende $.post sådan her:
$.post("test.php", { "post1": "something", "post2":"somethingelse" }, // those will be sent via post to test.php
function(data){// the returned data
console.log(data.return1); // here just logging to the console. **optional**
console.log(data.return2);
// complete your process
}, "json"); // specifying the type as json also optional
i din test.php
foreach($_POST as $key=> $for) {
if(!empty($for) && $key != 'send' && $key != 'title') {
$usercheck = "SELECT email FROM users WHERE email = '$for'";
$usercheck = $db->query($usercheck);
if($usercheck->num_rows > 0) {$x="1"; continue;}
if($usercheck->num_rows == 0){$x="2"; break;}
}
}
if($x == "2") {$data['message'] = $for." is not a regestered email";
echo json_encode($data); // echo to pass back to $.post .. json_encode() in case of using json
}
if($x == "1") { // valid - submit
$data['message'] = 'valid'; // pass the message as valid post
echo json_encode($data);
}
Husk:
Hvis du sender en formular, indsend for at tilføje event.preventDefault()
til din javascript-funktion for at håndtere formularen manuelt. her
du kan finde mere om det.