The example in this article describes the method of Javascript passing parameters based on the AJAX callback function. Share it with everyone for your reference, the details are as follows:
We introduced "Four ways to implement parameter transfer between html pages in javascript" before. Here is an analysis of ajax parameter transfer.
In Javascript, especially in AJAX, the callback function is often a function name with no place to put parameters. For example, the AJAX code below will call the callback function callback after success, but callback has parameters. How? What about passing the parameters in?
var callback = function(p1){ //do something } var ajaxSetting = { url: url, timeout:me.timeout, type: method, contentType: "application/json", dataType: "json", cache: false, async: async, data: p_data, success: callback }, error: function(p_request, p_status, p_err) { } };
The solution is to use anonymous functions:
success: function(result){ callback(p1_actual); }
Where pa_actual is a known parameter, which can be of function type.
I hope this article will be helpful to everyone in JavaScript programming.