Reputation: 5856
I am trying to post some data via ajax to php. The issue i have is the original data is pulled in via some java, like this:
var taskID = jQuery(this).attr('data-id');
var taskTitle = jQuery(this).attr('data-title');
var taskContent = jQuery(this).attr('data-content');
jQuery('.task_title').val(taskTitle);
jQuery('.task_description').val(taskContent);
When i then try and update this content in the browser (via a form), only the original data is getting posted back, and not the updated data.
Here is my ajax to post the data:
$( ".saveTaskEdit" ).click(function(event) {
var ta = $('.task_title').val();
var da = $('.task_description').val();
var taskID = $('.editTaskPanel').attr('data-id');
$.ajax({
type: "post",
url: "task-edit.php?t="+ ta + "&d=" + da + "&id=" + taskID,
contentType: "application/x-www-form-urlencoded",
success: function(responseData, textStatus, jqXHR) {
jQuery('p.status').text('Task Saved');
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
}
})
});
Is there any reason behind this?
Upvotes: 0
Views: 413
Reputation: 1436
You set type as "post" but send data as "get"; change your ajax , update "url" add "data" like this:
$( ".saveTaskEdit" ).click(function(event) {
var ta = $('.task_title').val();
var da = $('.task_description').val();
var taskID = $('.editTaskPanel').attr('data-id');
$.ajax({
type: "post",
data: { "t":ta,"d":da,"id":taskID},
url: "task-edit.php",
contentType: "application/x-www-form-urlencoded",
success: function(responseData, textStatus, jqXHR) {
jQuery('p.status').text('Task Saved');
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
}
})
});
Upvotes: 1