Click here to Skip to main content
16,019,873 members
Please Sign up or sign in to vote.
1.44/5 (3 votes)
onclick ajax call is not working i am not able to find the mistake please help me an quite new to the ajax jquery
Posted
Updated 13-Jul-16 1:52am
v3
Comments
Sergey Alexandrovich Kryukov 15-Jun-16 2:34am    
Sorry, we cannot see what do you have on your server side...
—SA
This is a Repost. You have already asked this couple of times. Update previous question if you want to more info.

1 solution

Why are you using e.preventDefault(); in the start of click event. Remember
JavaScript
e.preventDefault();

always prevents the browser to stop executing the below lines of a specific event.

Change the code to:

JavaScript
$("#submit-btn").on("click",function(e) {
  
  $.ajax({
    url: "https://ivr.callxl.com/callXLWeb/SendingEmail",
    type: "POST",       
    contentType: "application/json; charset=utf-8",
    data: "comment="+$("#cmessage").val() ,
    dataType: "text",
 
    success: function (data, textStatus, jqXHR) {
      if (data.success) {
        alert("successfully sent");
      } else {
        // handle error here...
      }
    },
    error: function(jqXHR, textStatus, errorThrown){
      alert(jqXHR.responseText);
      alert("error in server");
      console.log("Something really bad happened " + textStatus);
      $("#errorResponse").html(jqXHR.responseText);
    }
  });

e.preventDefault();
});
 
Share this answer
 
Comments
Anil_goswami 15-Jun-16 9:24am    
Similar question
http://www.codeproject.com/Questions/1106859/How-to-assign-textarea-value-to-varaiable-in-ajax

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900