I want to submit data from an html-form using jquery (there should be no redirect when submitting). I found this snippet online and changed the var-names so it fits my needs.
<script>
$(document).ready(function() {
$("#submit_btn").click(function() {
var url = $("#url").val();
var apiKey = $("#apiKey").val();
$("#returnmessage").empty(); // To empty previous error/success message.
// Checking for blank fields.
if (url == '' || apiKey == '') {
alert("Please Fill Required Fields");
} else {
// Returns successful data submission message when the entered information is stored in database.
$.post("api_test.php", {
url: url,
apiKey: apiKey,
}, function(data) {
$("#returnmessage").append(data); // Append returned message to message paragraph.
if (data == "Your Query has been received, We will contact you soon.") {
$("#form")[0].reset(); // To reset form fields on success.
}
});
}
});
});
</script>
The target-page "api.php" returns some text (php echo). Is it possible to display the echoed text like "Please Fill Required Fields" is displayed in the alert?
Aucun commentaire:
Enregistrer un commentaire