我正在使用 asp.net Web 服务 .asmx 来传输 json 数据。我有以下似乎不起作用的代码。
$.ajax({
type: "POST",
url: "../../App_Code/jsonWebService/getValue",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (output) {
alert(output);
$(config.captchaQuestion).html(output[0] + " + " + output[1] + " =");
$(config.captchaHidden).val(output[2]);
}
});
我在 asmx 文件的 jsonWebService.cs 中的代码是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using System.Web.Script.Serialization;
/// <summary>
/// Summary description for jsonWebService
// </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 jsonWebService : System.Web.Services.WebService {
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public Array getValue()
{
Random getRandom = new Random();
int rand1 = getRandom.Next(0, 9);
int rand2 = getRandom.Next(0, 9);
int sum = rand1 + rand2;
int[] jsonObject = new int[3] { rand1, rand2, sum };
return jsonObject;
}
}
我收到了禁止错误 403。在此先感谢。