Several different methods of passing parameters in JS

When performing web development, interacting with the front desk and background data is an unavoidable problem. Different business needs have different ways, and below is how many ways to use during the development process, write Come out with you, because of insufficient experience, there is a wrong place to welcome everyone.

1. Transfer through Window.Location.href or Document.Location.href, such as Window.Location.href = “http://www.ewcar.net?name=sun&age = 21 “; In this example, the parameters taken are Name and AGE, respectively, respectively, respectively, and can also add an anchor #, which can be specified to a location of the page.

2, pass through Ajax, the format is as follows:

$. Ajax {type: “post”, URL : “Test / INDEX”, DataType: JSON, DATA: $ (“# ORDERFORM”). Serialize (), Success: Function (D) {Alert (D)} error: function (d) {Alert (D)
   
wherein DATA represents data to be transmitted

3, passes through the POST method of Ajax, format As follows:

$ .POST ({“URL”, $ (“# ORDERFORM”). Serialize (), Function (D) {Alert (D. Msg);}});

Theoretically, this is also a AJAX method, but this method is relatively simple.
  4, the action method in the form table can also pass data, but the action method is relatively complete, can jump to the connection, or jump to text, pictures, videos, etc. Multimedia content, links in Action and WINDOW.LOCATION are the same.  
The above is the way I have used by the method, and if you encounter a new method later, it will be updated.
I hope this article will bring some help to everyone’s learning or work, and I hope to support Tumi cloud!

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment