Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
11
rated 0 times [  13] [ 2]  / answers: 1 / hits: 20056  / 8 Years ago, thu, february 11, 2016, 12:00:00

I want to send an email as soon as I click on html button. To do this task, I've written following code



HTML code:



<button onclick=sendEmail()>Send Email</button>
<p id=mailStatus></p>


Java Script Code:



function sendEmail()
{
$.ajax({
url: mail.php,
type: POST,
success: function(response) {
if (!response) {
alert(Something went wrong. Please try again);
return;
}

var parsedJSON = eval('('+response+')');

// If there's an error, display it.
if(parsedJSON.Error) {
// Handle session timeout.
if (parsedJSON.Error == Timeout) {
alert(Session timed out. Please login again.);
window.location.reload();
}
}
document.getElementById('mailStatus').innerHTML = Email Sent successfully;
}
});
}


The problem if when I click on Send Email button, I get an error message as



Uncaught ReferenceError: $ is not defined



Can someone please help??


More From » php

 Answers
71

As $.ajax is function of jQuery so you need to add jQuery in your file.



<script src=https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js></script>


Add this line above sendMail function.


[#63355] Tuesday, February 9, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leslijessalyng

Total Points: 650
Total Questions: 85
Total Answers: 109

Location: Croatia
Member since Mon, Sep 6, 2021
3 Years ago
leslijessalyng questions
Fri, Feb 21, 20, 00:00, 4 Years ago
Tue, Jul 30, 19, 00:00, 5 Years ago
Fri, Jul 5, 19, 00:00, 5 Years ago
Wed, Mar 13, 19, 00:00, 5 Years ago
;