English 中文(简体)
频率问题总是回归错误
原标题:jquery issue always return error

每当我管理比绍的ASPX页面时,我都收到内部服务器Error。 这是我从“网吧”中复制的一件事。

ASPX 页: 1

  <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="x.aspx.cs" Inherits="x" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Adventure Works</title>

       <style type="text/css">
       .loading
        {
            background-image: url( ajax-load.gif );
            background-repeat: no-repeat;
        }
       </style>

    <script src="/Scripts/jquery-1.3.2.js" type="text/javascript"></script>

    <script type="text/javascript">

        function CallService() {

            $( input[type=button] ).attr( disabled , true);
            $("#CustDetails").html(  );
            $("#CustDetails").addClass("loading");
            $.ajax({
                type: "POST",
                url: "GetVendor.asmx/GetVendorDetails",
                data: "{ ID : " + $("#txt_id").val() + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccess,
                error: OnError
            });

            function OnSuccess(data, status) {
                alert( success );

                $("#CustDetails").removeClass("loading");
               // $("#textVendorNameLookup").html(data.d);
                $( input[type=button] ).attr( disabled , false);
            }

            function OnError(request, status, error, response) {

                $("#CustDetails").removeClass("loading");
                $("#CustDetails").html(request.statusText);
                $( input[type=button] ).attr( disabled , false);

                //$("#textVendorNameLookup").html(request.statusText);
            }

        }
    </script>


</head>
<body>
    <form id="DocForm" runat="server">
    <div>

        <table style="width:31%;">
            <tr>
                <td>
                    Enter Contact ID</td>
                <td>
                    :</td>
                <td>
                    <input id="txt_id" value="12" type="text" /><input id="btnGo" type="button" 
                        value="Get Details" onclick ="CallService(); return false;"/></td>
            </tr>
            </table>
    <br />
    <div id="CustDetails" style="width: 60%; height: 75px;">
    &nbsp;
       </div>
    </div>
    </form>
</body>
</html>

ASMX

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

/// <summary>
/// Summary description for AdvService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 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 GetVendor : System.Web.Services.WebService {

    public GetVendor () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    public int GetVendorDetails(int id)
    {
        return id;

    }
}

The CS page;

  using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Telerik.Web.UI;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.Reflection;


public partial class x : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

    }

}

AHIA, Larry...

最佳回答

I think you just need to decorate those methods with [WebMethod] like so:

[System.Web.Script.Services.ScriptService]
public class GetVendor : System.Web.Services.WebService {

    [WebMethod]
    public int GetVendorDetails(int id)
    {
        return id;

    }
}
问题回答

“K”这一回答是头部的一个boot子......如果你具体说明数据表,数据以及网络服务中的名称必须相同。 感谢每个人的帮助/选择。 ——

询问它应当如何工作,

function CallService() {

    var CatID = {"ID": $( #txt_id ).val()}
    $( input[type=button] ).attr( disabled , true);
    $("#CustDetails").html(  );
    $("#CustDetails").addClass("loading");
    $.ajax({
        type: "POST",
        url: "AdvService.asmx/GetCtcDetails",
        data: JSON.stringify(CatID ),,
        contentType: "application/json; charset=utf-8",
        dataType: "json",         

        success: OnSuccess,
        error: OnError
    });

}

你可以使用VS。 在援引“雅氏”呼吁时,看到哪一部法典正在运行(如果有的话)。 这是开始解决“内部服务器电子”麻.问题的一个良好地方。

其次,如果你使用Firebug(网络开发中的“i plug”),你应明确加以核对,帮助在更大程度上用麻省电话进行脱浮。 更具体地讲到你的调查,看看看您的<编码>GetVendorDetails方法是否更像这种帮助。

using System.Web.Script.Services;
using System.Web.Services;
using System.Web.Script.Serialization;

...

[WebMethod]
[ScriptMethod(ResponseFormat=ResponseFormat.Json)]
public string GetVendorDetails(string Id) {
  // do your processing here to get your result
  return new JavaScriptSerializer().Serialize(yourObjectInstanceToBeJsonSerialized);
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签