Reputation: 5162
I am using the following code for sending ajax request but the request is not being sent. Can anyone help me to find the problem?
$("input.ub").click(function () {
console.log("I am here");
var id = $(this).attr('id');
var pid = "p" + id.substring(1, 2);
var text = $("#" + pid).text();
$("#" + pid).html('<input type="text" id="up" value="' + text + '" /><input type="button" id="req" value="Submit" />');
//Ajax request to be sent
$("#req").one("click", function () {
//var action = $("#postform").attr('action');
console.log("I am Second");
var form_data1 = {
post: $("#up").val(),
is_ajax: 1,
update: parseInt(id.substring(1, 2))
};
console.log($("#up").val());
$.ajax({
type: "POST",
url: "updatePosts.php",
data: form_data1,
success: function (response) {
if (response == "success") {
console.log("Succes MEssage");
$(location).attr('href', 'viewPosts.php');
} else console.log("You are failed here instead");
}
});
console.log("Request not sent");
return false;
});
I am getting the failure console messages. But i don't see any problem in the code.
Upvotes: 0
Views: 83
Reputation: 5192
You're returning "request not sent" even when it is successful. You need to use the error
setting in your AJAX call.
http://api.jquery.com/jquery.ajax/
Upvotes: 1
Reputation: 29
It looks like you may have forgotten a bracket after else...
$("input.ub").click(function(){
console.log("I am here");
var id = $(this).attr('id');
var pid="p"+id.substring(1,2);
var text=$("#"+pid).text();
$("#"+pid).html('<input type="text" id="up" value="'+text+'" /><input type="button" id="req" value="Submit" />');
//Ajax request to be sent
$("#req").one("click",function(){
//var action = $("#postform").attr('action');
console.log("I am Second");
var form_data1 = {
post: $("#up").val(),
is_ajax: 1,
update:parseInt(id.substring(1,2))
};
console.log($("#up").val());
$.ajax({
type: "POST",
url: "updatePosts.php",
data: form_data1,
success: function(response){
if(response == "success"){
console.log("Succes MEssage");
$(location).attr('href','viewPosts.php');
}
else { <=====HERE
console.log("You are failed here instead");
}
});
console.log("Request not sent");
return false;
});
Upvotes: 0