如何从javascript函数调用c#代码? [英] how to invoke c# code from javascript function ?

查看:72
本文介绍了如何从javascript函数调用c#代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想调用c#代码并对其执行一些操作。如何在javascript中调用c#代码。

i wanted to call c# code and perform some operation on it .how to call c# code in javascript.

推荐答案

首先你需要了解它们之间的根本区别服务器端代码(C#)和客户端代码(javascript)。 C#在Web服务器(如IIS)上运行,JavaScript在浏览器上运行(例如,firefox等)。它们都在完全断开连接的环境中工作,C#无法直接调用javascript函数,Javascript也无法直接调用C#代码。 Javascript调用C#服务器端代码的唯一机制是通过HTTP请求。由您决定如何对服务器进行HTTP调用,可能是您可以使用AJAX调用,也可以进行普通HTTP发布或获取请求。
First you need to understand the fundamental difference between Server Side Code (C#) and Client Side Code (javascript). C# runs on web server (like IIS) and JavaScript runs on browser( like ie,firefox etc). Both of them work in totally disconnected environment where C# can not make call to javascript function directly and same way Javascript can not make direct call to C# code. The only mechanism through which Javascript can make call to C# server side code is through HTTP request. Its up to you how you want to make HTTP call to the server, may be you can you use AJAX call or you can make Normal HTTP post or Get Request.


您好,


PageMethods就是答案,下面是类似查询的链接:



http://forums.asp.net/t/1938376.aspx?Call+C+function+from+javascript


执行此操作的常用技巧是使用AJAX从客户端发出请求并在服务器端调用Web方法。我非常喜欢使用jQuery来执行此操作,并且 here's [ ^ ]一篇方便的文章,展示了如何做到这一点。
A common technique for doing this is to use AJAX to issue a request from the client side and call a web method at the server side. I quite like using jQuery to do this, and here's[^] a handy article demonstrating how to do this.


这篇关于如何从javascript函数调用c#代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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