خرید بک لینک

Vote count: 0

I have a function to auto save text input like this:

saveToDB = function() {
      var form, id;
      form = $('#create_article');
      id = (form.attr('action')).split("/").pop(-1);
      $.ajax({
        url: '/admin/articles/' + id,
        type: 'POST',
        data: form.serialize(),
        beforeSend: function(xhr) {
          $('.form-status-holder').html('Saving...');
        },
        success: function(data) {
          var jqObj;
          jqObj = jQuery(data);
          $('.form-status-holder').delay(5000).hide();
        }
      });
    };
    $('form input, form textarea').on('input propertychange change', function() {
      var timeoutId;
      clearTimeout(timeoutId);
      retu timeoutId = setTimeout((function() {
        saveToDB();
      }), 5000);

The problem is that, this code only work with update action and I want to do the same with create action too. Two actions use the same create_article form. The button create and edit(update) is in index file before moving to the form. How do I notice what button was clicked and then do the saveToDB function then use the correct url(/admin/articles/' + id for update and /admin/articles/ for create)?

asked 43 secs ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 27 ارديبهشت 1395 ساعت: 9:14

صفحه بندی