0

I've got a very simple contact form that I am sending with an AJAX call...the only problem is that it isn't sending properly and I'm not catching any errors.

Relevant chunk of JavaScript:

$('#feedbackSubmit').click(function() {
//send the stuff
$.ajax({
  type: "GET",
  url: "./br.php",
  data: { 'name': $('#fName').val(),
          'email': $('#email').val(),
          'subject': $('#subject').val(),
          'message': $('#message').val()
    }
});

Relevant chunk of PHP:

$fName = $_GET["name"];
$from = $_GET["email"];
$sub = $_GET["subject"];

if($_GET['desc']) {
  $desc = $_GET["desc"];
  //formatting of the body of the mail
}

else {
  $desc = $_GET["message"];
  //format the body again
}

Maybe I'm just burned out looking at this, but I can't seem to find what's causing the problem...

Notes: Tried with GET and POST...tried with PHP file at level of call and level of template.

mikedugan
  • 2,393
  • 3
  • 19
  • 24
  • First thing first — relative paths in AJAX: have you checked that it is indeed calling the right file (and that the file exists)? – Terry Oct 29 '13 at 17:09
  • Most of the time, contact forms use `POST` and not `GET`. – Funk Forty Niner Oct 29 '13 at 17:10
  • yup - the file is included by a page residing at the same level as br.php – mikedugan Oct 29 '13 at 17:10
  • Also, check your browser's console log. Are any errors being thrown? And you can try manually making the AJAX call by accessing `br.php` with the stated variables, e.g. `br.php?name=John&email=johndoe@gmail.com&...`. Do you get anything out of it? – Terry Oct 29 '13 at 17:11
  • 1
    You may want to remove that trailing `,` after `$('message').val()` – cmorrissey Oct 29 '13 at 17:12
  • caught the `,` when I was posting it, forgot to update the question...and console log yields nothing. – mikedugan Oct 29 '13 at 17:12
  • Try attaching a callback for your AJAX call, e.g. success or error. What happens? See here for some ideas: http://stackoverflow.com/questions/377644/jquery-ajax-error-handling-show-custom-exception-messages – Terry Oct 29 '13 at 17:13
  • @mike What is your form's method set to, or are you using one (method) to start with? – Funk Forty Niner Oct 29 '13 at 17:13
  • add a callback function to your ajax and alert out what you get ie `, function(data){ alert(data); }` try echoing out anything in your br.php at different spots in your code to see where its breaking. – cmorrissey Oct 29 '13 at 17:15
  • @Fred-ii- no method on the form, handling it with an event listener attached to the submit button – mikedugan Oct 29 '13 at 17:19
  • Callbacks and echoes yield nothing...seems weird even though it is ajax...though admittedly I don't work with ajax often – mikedugan Oct 29 '13 at 17:34

0 Answers0