1
我創建了一個REST API,我把它從jQuery的是這樣的:數字在API ASP.NET URL參數和jQuery
$scope.apiCall = function (_type) {
$.ajax({
type: "GET",
url: "./handler/api.ashx/" + _type,
cache: false,
dataType: "json",
contentType: "application/json; charset=UTF-8",
success: function (datas, textStatus, xhr) {
//my code
},
error: function (xhr, textStatus, errorThrown) {
console.log(errorThrown);
}
});
}
我的API是這樣的:
if (Request.RequestType == "GET")
{
string RawUrl = Request.RawUrl;
string splitter = "api.ashx/";
string SubRawUrl = RawUrl.Substring(RawUrl.IndexOf(splitter) + splitter.Length);
string[] Parameters = SubRawUrl.Split('/');
if (Parameters.Length == 1 && Parameters[0] != "")
{
//My Code
Response.Write(resp.ToJSON());
Response.ContentType = "application/json";
}
}
但在我的API,在Request.RawUrl返回此:
/handler/api.ashx/Contact?_=1493885783112
其中 「/聯繫人」 是在$ scope.apiCall功能我 「_type」 參數。
我查了一下,在調試模式下,「_type」,它返回「聯繫」,結果,爲什麼我在URL有「= 1493885783112」?
Chrome。使用$阿賈克斯之前,我使用$ .getJSON和它的工作完美,沒有數字,但我需要找回響應和我沒有找到如何使用$ .getJSON做到這一點 –