0

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?

danyo
  • 5,686
  • 20
  • 59
  • 119
  • 1
    your `type` is `post`. yet you are using parameters in your `url` property. why not just use data property? – Gavindra Kalikapersaud Jul 24 '17 at 17:13
  • When you are calling the first activity ? – Tamilvanan Jul 24 '17 at 17:14
  • @TamilvananN first activity is the setting of the data on page load – danyo Jul 24 '17 at 17:16
  • Have you checked the values before sending into the ajax method ? – Tamilvanan Jul 24 '17 at 17:20
  • It seems like you're mixing `GET` and `POST`. Appending parameters to a URL is how you send via `GET` - to send as `POST` you'll likely want an object which you'd pass as the `data` parameter. [See here for more information](https://stackoverflow.com/questions/5046930/jquery-send-string-as-post-parameters). – Tyler Roper Jul 24 '17 at 17:21

1 Answers1

1

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);
        }
    })
});
aidinMC
  • 1,415
  • 3
  • 18
  • 35