$.ajax() url path problem

hi i have wordpress theme and i created function to put the contact form within the dropdown menu the contact from work and send email without any problem.

Added the ajax jquery code until when i click on Send message the page don’t refresh.

but i want how i use the $.ajax(url) property. because my php, html and ajax code all within one function. i know use url when php mailer script from different folder but if all codes within one file how use url property.

Also i think my ajax code very poor please help me for correct my code until work correctly.

function YPE_bscontact() {
    if(empty($nameErr) && empty($emailErr) && empty($messageErr)) {
	$to = 'rerraw@gmail.com';
	$headers   = array();
	$headers[] = "MIME-Version: 1.0";
	$headers[] = "Content-type: text/plain; charset=iso-8859-1";
	$headers[] = "From: {$name} <{$email}>";
	$headers[] = "Bcc: JJ Chong <bcc@domain2.com>";
	$headers[] = "Reply-To: {$name} <{$email}>";
	$headers[] = "Subject: {$subject}";
	$headers[] = "X-Mailer: PHP/".phpversion();

	if(mail($to, $subject, $email, implode("\r\n", $headers))){
		$sucess = '<p class="success">Your message has been sent successfully!</p>';
	} else {
		$fail .= '<p class="error">Unable to send email. Please try again!</p>';
    <form id="ajax-contact" class="navbar-form" action="" method="POST">
        <h4>Contact us</h4>
        <div class="success">'.$sucess.'</div>
        <div class="error">'.$fail.'</div>
        <input type="text" name="name" class="form-control" id="nameBsn" value="'.$name.'" placeholder="Username">
        <div class="error">'.$nameErr.'</div>
        <input type="text" name="email" class="form-control" id="emailBsn" value="'.$email.'" placeholder="Eamil">
        <div class="error">'.$emailErr.'</div>
        <input type="text" name="subject" class="form-control" id="subjectBsn" value="'.$subject.'" placeholder="Subject">
        <textarea name="message" id="messageBsn" class="form-control" rows="5" cols="22" placeholder="Message">'.$message.'</textarea>
        <div class="error">'.$messageErr.'</div>
    <script type="text/javascript">
	var name    = jQuery('#nameBsn').val();
	var email   = jQuery('#emailBsn').val();
	var subject = jQuery('#subjectBsn').val();
	var message = jQuery('#messageBsn').val();
	jQuery('#ajax-contact').submit(function(event) {
		type: jQuery(this).attr('method'),
		data: "{'name':'" + name+ "', 'email':'" + email+ "', 'subject':'" + subject+ "', 'message':'" + message+ "'}",
		success: function(data) {
		error: function (data) {

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.