从javascript(.js文件)调用服务器端函数 [英] calling serverside function from javascript (.js file)

查看:85
本文介绍了从javascript(.js文件)调用服务器端函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从js文件中调用服务器端函数,但没有起作用
例如javascript.js

I tried to call serverside function from js file but didnot work
for example in javascript.js

$.ajax({
                     type: "POST",             
                     url: "Default.aspx/UploadAll",                
                     data: "", 
                     contentType: "application/json; charset=utf-8",
                     dataType: "json",
                     async: true,
                     cache: false,
                     success: function (msg) {
                     
                    }                     
               });


当我在aspx文件中添加此功能时,效果很好,但在js文件中却不行

在Default.aspx.cs的代码背后


when i add this function in aspx file it works fine but not in js file

In The codebehind Default.aspx.cs

[System.Web.Services.WebMethod]
  public static void UploadAll()
  {
  }


有没有办法从js文件本身调用服务器端函数,如何从js文件调用服务器端函数?

在此先感谢


Is there any way to call server side functions from js file itself, how to call server side function from js file?

Thanks in advance

推荐答案

.ajax({ 类型:" , 网址:" , 数据:" , contentType:" , dataType:" , 异步: true , 缓存: false , 成功:功能(msg){ } });
.ajax({ type: "POST", url: "Default.aspx/UploadAll", data: "", contentType: "application/json; charset=utf-8", dataType: "json", async: true, cache: false, success: function (msg) { } });


当我在aspx文件中添加此功能时,效果很好,但在js文件中却不行

在Default.aspx.cs的代码背后


when i add this function in aspx file it works fine but not in js file

In The codebehind Default.aspx.cs

[System.Web.Services.WebMethod]
  public static void UploadAll()
  {
  }


有没有办法从js文件本身调用服务器端函数,如何从js文件调用服务器端函数?

在此先感谢


Is there any way to call server side functions from js file itself, how to call server side function from js file?

Thanks in advance


CP来为您提供救援

使用Ajax从客户端调用服务器端代码 [ ^ ]

如何:实现ICallBackEventHandler(从客户端调用服务器端代码) [ ^ ]
Here comes CP for your rescue

Calling Server Side Code from Client Side using Ajax[^]

How to: Implement ICallBackEventHandler (calling server side code from client side)[^]


这篇关于从javascript(.js文件)调用服务器端函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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