以下のASPXページを実行するたびに、内部サーバーエラーが発生します。これは、私がウェブからコピーしたものです&この問題を引き起こしているのを把握しようとしてこれを元に取り除きました。jquery問題は常にエラーを返します
ASPXページ:
<%@ 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;">
</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;
}
}
CSページ。
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、 ラリー...
、それが動作するはずこれを試してみてください? – Vadim
あなたは、そのasp.netページでJSONが正しく返されることはないことを知っていますか? JSONとして整形されていない数字だけです。そのためには、JSON.NET http://json.codeplex.comを使用してください。そして、 'GetVendorDetails'はWebMethodでさえありません! – balexandre
@balexandre Json.netは必要ありません。私の例を一瞬で掲載しています。 – Tahbaza