Problems related to passing variable parameters in JavaScript calls and solutions, and javascript Problems

Source: Internet
Author: User

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> 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.