編輯:實際的錯誤,我從網絡上獲取的數據:返回谷歌地圖標記
「無效的JSON原始:位置」
代碼調用它:
function AddMarkerAndPanTo(latLng, map) {
var marker = new google.maps.Marker({
position: latLng,
map: map
});
var x = marker.position;
$.ajax({
type: "POST",
url: '@Url.Action("AddMarker", "Map")', // Map Controller, AddMarker Action
data: JSON.stringify({ "position": x }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
if (data.done)
alert("Marker added");
else
alert("MARKER FAILED");
}
});
map.panTo(latLng);
}
使用貼在它下面的圖模型中的服務器側的功能:
[HttpPost]
public ActionResult AddMarker(LatLngViewModel position)
{
if (position != null)
return Json(true, JsonRequestBehavior.AllowGet);
else
return Json(false, JsonRequestBehavior.AllowGet);
}
視圖模型:
public class LatLngViewModel
{
double latitude { get; set; }
double longitude { get; set; }
}
我嘗試使用與報價和而對位置,字符串化的結果,或者用的toJSON其返回()。試着拼接toSend和各種引號等。在這一點上,我不知道是什麼原因導致它,我沒有其他解決方案。欣賞任何幫助解決這個問題,併發送血腥的座標回來綁定到模型莫名其妙。
哪個服務器端語言,你用? – scaisEdge
這是C#,使用ASP.NET – Ben