Firefog Firefog - 1 year ago 151
jQuery Question

JQuery form submit not calling success

After click on submit

works but it does not call
also there is no console error . The data also submit to database correctly ! Then why it not call the
. Please Help

$(function() {
//hang on event of form with id=ticketForm
$("#ticketForm").submit(function(e) {
//prevent Default functionality
//get the action-url of the form
var actionurl = e.currentTarget.action;
var form = $('#ticketForm');
var submit = $('#submite');

url: actionurl,
type: "POST",
data: $("#ticketForm").serialize(),
dataType: "json",
contentType: 'application/json; charset=utf-8',
cache: false,
beforeSend: function(e) {
success: function(e) {
submit.html("Booking Completed !");
//get the message from booking.php and show it.
var msg = $.ajax({
type: "GET",
url: actionurl,
async: false
document.getElementById("success-message").innerHTML = msg;
setTimeout(function() { // wait for 3 secs(2)
location.reload(); // then reload the page.(3)
}, 3000);
error: function(e) {

Console Message

Object {readyState: 4, responseText: "<strong>Seat Booked Successfully</strong>", status: 200, statusText: "OK"}

Answer Source

In your AJAX call settings you set dataType to json, but in return you provide a string.

dataType (default: Intelligent Guess (xml, json, script, or html)) The type of data that you're expecting back from the server. If none is specified, jQuery will try to infer it based on the MIME type of the response

So, you have two solutions:

  1. Provide a valid JSON in response
  2. Do not ask for JSON by changing your dataType value (to html), or by removing it.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download