Если кто-то может указать, что здесь не так, я бы, конечно же, его оценил. Я могу установить точку останова в веб-методе, и он попадает, но он всегда ошибочно.jQuery ajax json webservice error
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AJAX_Test._Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>AJAX Test</title>
<script src="Scripts/jquery-1.7.min.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<button id="theButton">Click Here</button>
</form>
<script type="text/javascript">
$(function() {
$("#theButton").on("click", function() {
$.ajax({
type: "POST",
url: "AjaxWebService.asmx/HelloWorld",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: "{}",
success: AjaxSucceeded,
error: AjaxFailed
});
});
});
function AjaxSucceeded(data, status) {
alert("success");
}
function AjaxFailed(jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
</script>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
namespace AJAX_Test
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class AjaxWebService : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}
Какая ошибка? – jrummell
Каковы ошибки? – MilkyWayJoe
Я изменил код, и теперь третий arg выдает ошибку внутреннего сервера. Я вижу, что есть ответ ниже, связанный с [ScriptService], и я посмотрю на это. –