2011-06-24 47 views
4

我一直在尋找這一段時間,看不到問題出在哪裏。任何幫助是極大的讚賞。無效的Web服務調用,參數缺失值

[WebMethod(true)] 
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] 
public static string neighbourhoodTeam(string force, string neighbourhood) 
{ 
    //StreamManager streamMan = new StreamManager(); 
    //return streamMan.StreamManagerUrlHandler("http://policeapi2.rkh.co.uk/api/" + force + "%2F" + neighbourhood + "%2F" + "people"); 
    return neighbourhood + force; 
} 

的jQuery:

function getOfficers(force, neighbourhood) { 
    $.ajax({ 
     type: "GET", 
     contentType: "application/json; charset=utf-8", 
     url: "../police/crimerequest.aspx/neighbourhoodTeam", 
     data: JSON.stringify({ "force": force, "neighbourhood": neighbourhood }), 
     dataType: "json", 
     success: function (data) { 
      var results = $.parseJSON(data.d); 
      $.each(results, function (i) { 
       businessCards.push(generateOfficerBusinessCard(
          results[i].name, 
          results[i].rank, 
          results[i].contact_details.mobile, 
          results[i].contact_details.tel, 
          results[i].contact_details.email)) 
      }); 
      PoliceApp.businessCardsPlaceHolder.html(businessCards.toString()); 
     }, 
     error: function (xhr, ajaxOptions, thrownError) { 
      alert(xhr.status); 
      alert(thrownError); 
      alert(xhr.responseText); 
      return false; 
     } 
    }); 
} 

我也得到:{"Message":"Invalid web service call, missing value for parameter: \u0027force\u0027.","StackTrace":"

回答

5

嘗試在阿賈克斯與PARAMS發送processData: false。 jQuery將默認再次進行字符串化。

使用提琴手或類似的工具檢查網絡流量,看看實際發送到您的網絡服務。

+0

我刪除了stringify並允許jquery處理數據。發送給服務的是:強制蘇克塞斯社區CC2NH7,但現在我得到無效的json原語。 – XGreen

+0

試試這個:把你自己搞定,並把processData設置爲false。 – Mrchief

+1

我把我自己串起來,並將processData設置爲false。現在我得到的是{「Message」:「無效的Web服務調用,參數缺失值:\ u0027force \」,「StackTrace」:「發送的參數現在是:{」force「:」sussex「,」neighb ... – XGreen

相關問題