将变量传递给现有的javascript [英] Pass variables to an existing javascript

查看:75
本文介绍了将变量传递给现有的javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我使用Asp.Net进行网站构建。我想直接从c#代码将变量或列表传输到javascript。此外,javascript存在,我想做的就是以某种方式在这个javascript中注入一个带有变量的新行,这样我就可以直接在javascript中使用它们了。如果这是另一种简单的方法来做这样的事情请帮助我。



谢谢

Hello,
I hava a site build with Asp.Net. I want to transfer a variables or a list to a javascript direct from c# code. Also, the javascript exist, all i want to do is to "inject" somehow in that javascript a new line with the variables so i can use them direct in javascript. If it is another easy way to do something like this please help me.

Thanks

推荐答案

一个你可以做的是,尝试对服务器进行ajax调用&在ajax成功中将服务器中的参数绑定到javascript中的任何gobal变量。这可以帮到你。



One thing you can do is, try making an ajax call to the server & on the ajax success bind the parameters from the server to any gobal variable in your javascript. This would help you out.


.ajax({
url : // 您对服务器的调用,
数据: // 如果需要传递参数
sucess:function(data){ // 此处数据是服务器调用方法的接收值
// 执行类似绑定到全局变量的操作,以便在脚本中的任何位置重用。
}

});
.ajax({ url: //your call to server, data: //if any needed to pass as parameter sucess: function(data){ //here data is the received values from server call method //do something like bind values to a global variable to be reused any where in the script. } });



谢谢

:)


Thanks
:)


注入不是以某种方式,而是使用脚本函数参数。如果您没有这些参数,请介绍它们。 :-)



-SA
"Inject" not somehow, but using a script function parameters. If you don't have those parameters, introduce them. :-)

—SA


这篇关于将变量传递给现有的javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆