简体   繁体   English

Ajax调用返回500内部服务器错误

[英]Ajax call returning 500 internal server error

I am trying to make a google map appear on my web page without using another page load. 我正在尝试在不使用其他页面加载的情况下使Google地图出现在我的网页上。 I keep getting an error when I try to call a web method that i have. 尝试调用我拥有的Web方法时,我总是收到错误消息。 Here is the code that I use to call the web method: 这是我用来调用Web方法的代码:

HTML 的HTML

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

Javascript: 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# C#

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

I get there error as soon as the c# method is called. 一旦调用c#方法,我就会收到错误消息。 here is the error message: 这是错误消息:

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)"

Any suggestions? 有什么建议么?

Have a look at the request in Fiddler , and see what's actually going across the wire. 查看Fiddler中的请求,并查看实际情况。 It should help you isolate the problem. 它应该可以帮助您隔离问题。

Also, have you tried setting a breakpoint in your web method? 另外,您是否尝试过在Web方法中设置断点? Does it even make it to that point? 它甚至做到了这一点吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 对Webmethod的Ajax调用给出错误500内部服务器错误 - Ajax call to webmethod gives ERROR 500 Internal server error Ajax调用返回内部500错误 - Ajax call returns internal 500 error 执行Ajax时出现500内部服务器错误 - 500 Internal server error when executing Ajax 500内部服务器错误与Ajax请求 - 500 Internal Server Error With Ajax Request 调用GetResponse()引发(500)内部服务器错误 - Call to GetResponse() is throwing (500) Internal Server Error 测试AJAX第一次在WebMatrix(C#)中,服务器返回内部错误500 - Testing AJAX For the first time in WebMatrix (C#), Server returning internal error 500 MVC4 - Ajax.ActionLink()GET返回500内部服务器错误 - MVC4 - Ajax.ActionLink() GET returning 500 internal server error Ajax请求asp.net mvc控制器返回500 - 内部服务器错误 - Ajax request for asp.net mvc controller returning 500 - internal server error Ajax 调用资源加载失败:服务器响应状态为 500(内部服务器错误) - Ajax call with a failed to load resource: the server response with a status 500 (internal server error) jQuery ajax调用将无法访问控制器:无法加载资源:服务器以状态500(内部服务器错误)响应 - Jquery ajax call wont access the controller: Failed to load resource: the server responded with a status of 500 (Internal Server Error)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM