Problems related to passing variable parameters in JavaScript calls and solutions, and javascript Problems
Example
There is a js method that receives parameters:
Copy codeThe Code is as follows:
Function f1 (myValue) {alert (myValue );}
There is a variable:
Copy codeThe Code is as follows:
Var passValue = "Hello World ";
When calling this method (I used it when Ajax was submitted ):
@ Ajax. ActionLink ("text", "controller", new {parameter}, new AjaxOptions () {HttpMethod = "post", OnSuccess = "f1 (PassValue )"})
Pay attention to the final OnSuccess. If you directly drop the variable, the variable will be considered as a string
If it is changed to OnSuccess = "f1 (" + PassValue + ")", no.
I searched for the escape characters.
OnSuccess = "f1 ('" + PassValue + "')"
So there is no problem.
However, I did not pay attention when calling Ajax above. Here I just want to pass parameters to the Asynchronous Method f1 ().
So you don't need to use @ Ajax to change it to the common A tag. Otherwise, the Controller will be called twice.
Ps: js calls methods as parameters
<! DOCTYPE html>