【问题标题】:Ajax call returning 500 internal server errorAjax 调用返回 500 内部服务器错误
【发布时间】:2011-04-01 16:08:53
【问题描述】:

我正在尝试在不使用其他页面加载的情况下让谷歌地图出现在我的网页上。当我尝试调用我拥有的 Web 方法时,我不断收到错误消息。这是我用来调用 web 方法的代码:

HTML

<form id="cSharpServerSideForm" runat="server">
        <asp:ScriptManager ID="_scriptManager" runat="server">
          <Services>
            <asp:ServiceReference Path="WebServices/Ajax.asmx" />
          </Services>
        </asp:ScriptManager>
    </form>

Javascript:

//To get webservice (located in document.ready)
vars.service = MyMap.WebServices.Ajax;

getInputForCenterMap = function () {
//The Jarray used
var jArrayCoords;  

var ResponseArray;

//Input values
tCity = "";
tState = "";
tZip = "";

//Gets input values
tCity = $('#cityInput').val();
tState = $('#stateInput').val();
tZip = $('#zipInput').val();

//Checks to see inputs entered
if (tZip == "" && tState == "" && tCity == "") { //Nothing entered
    //Error message
    $('#cszErrorMessage').html("Please enter a city/state or zip code");
} else {
    //In case of errors
    try {
        //Check what has been entered
        if (tZip == "") {    //City and state entered
            //Init array call
            jArrayCoords = new Array(2);
            //Adds city and state to array
            jArrayCoords[0] = tCity;
            jArrayCoords[1] = tState;

        } else {    //Zip entered
            //Init array call
            jArrayCoords = new Array(1);
            //Adds city and state to array
            jArrayCoords[0] = tZip;
        }

        //Calls web service
        vars.service.getMapCenterCoords(jArrayCoords, function (response) {
            //Turns response into a jarray
            responseArray = new Array(response);
            //Rest of code
        });

    } catch (error) {
        //Error message
    }
}

C#

  public double[] getMapCenterCoords(JArray userLocationInformation)
    {
      //Method information
    }

只要调用 c# 方法,就会出现错误。这是错误消息:

500 Internal Server Error

"System.ArgumentException"

"Argument is not a JToken."

" at Newtonsoft.Json.Linq.JContainer.EnsureValue(Object value) at Newtonsoft.Json.Linq.JContainer.System.Collections.IList.Add(Object value) at System.Web.Script.Serialization.ObjectConverter.AddItemToList(IList oldList, IList newList, Type elementType, JavaScriptSerializer serializer, Boolean throwOnError) at System.Web.Script.Serialization.ObjectConverter.ConvertListToObject(IList list, Type type, JavaScriptSerializer serializer, Boolean throwOnError, IList& convertedList) at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject) at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject) at System.Web.Script.Services.WebServiceMethodData.StrongTypeParameters(IDictionary`2 rawParams) at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary`2 parameters) at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams) at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)"

有什么建议吗?

【问题讨论】:

    标签: c# javascript ajax


    【解决方案1】:

    查看Fiddler 中的请求,看看实际发生了什么。它应该可以帮助您隔离问题。

    另外,您是否尝试过在 Web 方法中设置断点?它甚至到了那个地步吗?

    【讨论】:

    • 我曾尝试使用提琴手,但我不太了解它,所以除了我在 firebug 中遇到的相同错误外,我无法从中得到太多。我也试过web方法的断点,并没有进入方法
    猜你喜欢
    • 2016-09-16
    • 2016-06-19
    • 2016-09-16
    • 2019-11-12
    • 1970-01-01
    • 2016-08-20
    • 1970-01-01
    • 2023-03-19
    • 2013-02-26
    相关资源
    最近更新 更多