Click here to Skip to main content
15,904,926 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Am having form inside the label type any message and click on "submit" it should call ajax and save in db

This is the Html code

<form role="form">

<label for="message">Message:</label>
<textarea class="form-control" id="cmessage"></textarea>


<button type="submit" id="msg-btn" class="btn btn-primary pull-right">Submit</button>
</form>

this is js code

$(document).ready(function() {


/* message */

What I have tried:

$(document).on("click","#msg-btn", function() {

$.ajax({
type: "POST",
url: "https://ivr.callxl.com/callXLWeb/SendingEmail",
data: "comment="+$("#cmessage").val(),
dataType: "text",

success: function(data, textStatus, jqXHR) {
if(data.success){
alert("success fully send");
}
else {

alert("Invalid Message");
}
},
// If there was no resonse from the server
error: function(jqXHR, textStatus, errorThrown){
alert(jqXHR.responseText);
console.log("Something really bad happened " + textStatus);
$("#errorResponse").html(jqXHR.responseText);

},
});
});
Posted
Updated 3-Jun-16 1:58am
Comments
ZurdoDev 3-Jun-16 7:52am    
All you have to do is debug it. We can't run this code so you have to figure out where it is going wrong. Then we can help you.
Member 12563568 3-Jun-16 8:39am    
i did but it stopped near ajax itself and moving to other function
ZurdoDev 3-Jun-16 8:40am    
I don't know what that means. But again, we can't run your code so first figure out what it is doing.
Member 12563568 3-Jun-16 8:48am    
ok thankyou.how to do step by step debug?
ZurdoDev 3-Jun-16 8:51am    
Put a breakpoint in your code, run it, and then use step into or step over.

1 solution

Try this method

JavaScript
$('#msg-btn').click(function(){
     $.ajax({
           type: 'POST',       
           contentType: "application/json; charset=utf-8",
           url:"https://ivr.callxl.com/callXLWeb/SendingEmail",
           data: {comment= $("#cmessage").val()},
           dataType: "json",
           async: true,
          success: function (data) {
               alert("success fully send");
          },
          error: function () {
          console.log("there is some error");
         }

    });
});
 
Share this answer
 

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