简体   繁体   中英

Calling jQuery in Ajax response

I want to call a jQuery function that acts upon a form in AJAX response.

How do I do it???

jQuery Function

$(document).ready(function (e) {
  $("#load_timetable").on('submit',function(e) {
    e.preventDefault();
    $.ajax({
      url: "load_timetable.php",
      type: "POST",
      data:  new FormData(this),
      contentType: false,
      cache: false,
      processData: false,
      success: function(data) {
        $("#time_table").html(data);
      },
      error: function() {}          
    });
  });
});

Another AJAX Function

$(document).on("click", ".open-viewFacultyDialog", function () {
  var uid = $(this).data('id');
  $('#update').click(function() {    
    var ajaxRequest;
    try { 
      ajaxRequest = new XMLHttpRequest();
    }
    catch (e) { 
      try { 
        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); 
      }
      catch (e) {
        try { 
          ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); 
        }
        catch (e) { 
          alert("Your browser broke!"); 
          return false; 
        }
      }
    }
    ajaxRequest.onreadystatechange = function() {
      if(ajaxRequest.readyState == 4) {
        **//I would like to call JQUERY here**
        document.getElementById("update_action_response").innerHTML = "";
        var ajaxDisplay = document.getElementById('update_action_response');
        ajaxDisplay.innerHTML = ajaxRequest.responseText;
      }
    }
    var dept_slot = document.getElementById('dept_slot').value;
    var subject = document.getElementById('subject').value;
    var faculty1 = document.getElementById('faculty1').value;
    var faculty2 = document.getElementById('faculty2').value;
    var faculty3 = document.getElementById('faculty3').value;

    var queryString="?id="+uid+"&dept_slot="+dept_slot+"&subject="+subject+"&faculty1="+faculty1+"&faculty2="+faculty2+"&faculty3="+faculty3;
    ajaxRequest.open("GET", "update_timetable.php"+queryString, true);
    ajaxRequest.send(null);
  });
});

In simple I would like to reload the contents after updation without page reload by submitting the same parameters that are used to load the contents before update.

Use Promise method which is already defined in jquery.you can use it if data transfer successfully. such that if promise returns true then perform this task.else other task.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM