无法使用Jquery Ajax调用调用Web服务方法 [英] Unable to Call Web Services Method Using Jquery Ajax Call

查看:101
本文介绍了无法使用Jquery Ajax调用调用Web服务方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我试图从同一解决方案本身的Web服务(.asmx)中调用一个方法(我使用的是Visual Studio 2012 Web Express)使用Jquery Ajax Calls,控件命中方法并返回jquery调用。请告诉我需要在网络配置或任何地方进行哪些更改。

< script type =   text / javascript src =   http:/ /code.jquery.com/jquery-1.8.2.js\"></script> 
< script type = text / javascript>
$( document )。ready( function (){
$(< span class =code-string> #btnUploadFile)。click( function (e){
调试器;
var filename = $( #<%= flUpload.C​​lientID%>)。val();
}
$ .ajax({
type:' POST'
// data:{'FileName':+ filename +},
url: UploadEmployee.asmx / Test
contentType: application / json; charset = utf-8
dataType: json
成功: function (msg){
alert(msg);
}
});
} );
});
< / script>





 < span class =code-keyword>使用 Sonata.Finance.BusinessObjects; 
使用 Sonata.Finance.Services;
< span class =code-keyword>使用系统;
使用 System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
使用 System.Globalization;使用 System.IO;
System.Linq;
使用 System.Web;
使用 System.Web.Script.Services;
使用 System.Web.Services;

namespace FinanceWebApplication.WebServices
{
/// < summary >
/// UploadEmployee $ b的摘要说明$ b /// < < span class =code-summarycomment> / summary >
[WebService(Namespace = http://tempuri.org/)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem( false )]
// 要允许使用ASP.NET AJAX从脚本调用此Web Service,请取消注释以下行。
[System.Web.Script.Services .ScriptService]
public class UploadEmployee:System.Web.Services.WebService
{

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string Test()
{
return ;
}
}





}

解决方案

document )。ready( function (){


#btnUploadFile)。click( function (e){
debugger ;
var filename =

#<%= flUpload.C​​lientID%> ).val();
}


Hi,

I am trying to call a method from web service(.asmx) present in same solutions itself(I am using Visual Studio 2012 Web Express) using Jquery Ajax Calls, the control hitting the method and getting back to jquery call. Please tell what changes I need to make In web configue or in any place.

<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
 <script type="text/javascript">
        $(document).ready(function () {
                  $("#btnUploadFile").click(function (e) {
                debugger;
                var filename=$("#<%=flUpload.ClientID%>").val();
              }
                $.ajax({
                    type: 'POST',
                    //data: "{'FileName': "+ filename +"}",
                    url: "UploadEmployee.asmx/Test",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) {
                        alert(msg);
                    }
                });
            });
        });
    </script>



using Sonata.Finance.BusinessObjects;
using Sonata.Finance.Services;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;

namespace FinanceWebApplication.WebServices
{
    /// <summary>
    /// Summary description for UploadEmployee
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    [System.Web.Script.Services.ScriptService]
    public class UploadEmployee : System.Web.Services.WebService
    {

        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string Test()
        {
            return "Hi";
        }
    }



}

解决方案

(document).ready(function () {


("#btnUploadFile").click(function (e) { debugger; var filename=


("#<%=flUpload.ClientID%>").val(); }


这篇关于无法使用Jquery Ajax调用调用Web服务方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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