2011-04-01 151 views
0

我想使谷歌地圖出現在我的網頁上,而不使用其他頁面加載。當我嘗試調用我擁有的Web方法時,我總是收到錯誤消息。下面是我用它來調用Web方法的代碼:Ajax調用返回500內部服務器錯誤

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

有什麼建議?

回答

0

查看Fiddler中的請求,並查看實際發生的情況。它應該可以幫助你隔離問題。

另外,你有沒有嘗試過在你的web方法中設置斷點?它甚至能達到這一點嗎?

+0

我試圖使用提琴手,但我不知道它那麼好,所以我不能從它得到很多,除了我在螢火蟲中得到同樣的錯誤。我也在Web方法中嘗試了一個斷點,但它沒有將其放入方法中 – 2011-04-01 16:35:00

相關問題