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?

5
  • 1
    your type is post. yet you are using parameters in your url property. why not just use data property? Commented Jul 24, 2017 at 17:13
  • When you are calling the first activity ? Commented Jul 24, 2017 at 17:14
  • @TamilvananN first activity is the setting of the data on page load Commented Jul 24, 2017 at 17:16
  • Have you checked the values before sending into the ajax method ? Commented Jul 24, 2017 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. Commented Jul 24, 2017 at 17:21

1 Answer 1

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);
        }
    })
});
Sign up to request clarification or add additional context in comments.

1 Comment

@Santi is it ok now ? ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.