Home > Web Front-end > JS Tutorial > Analysis of Javascript passing parameters based on AJAX callback function_javascript skills

Analysis of Javascript passing parameters based on AJAX callback function_javascript skills

WBOY
Release: 2016-05-16 15:25:42
Original
1106 people have browsed it

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) {
   }
};

Copy after login

The solution is to use anonymous functions:

success: function(result){
   callback(p1_actual);
}

Copy after login

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.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template