1
我試圖學習MVC4 Web API。我正在從VS2010運行我的項目。從項目外的普通HTML文件調用MVC4 Web API
我的項目URL爲localhost:31735
當直接調用瀏覽器從自身的WebAPI。它像localhost一樣工作:31735/api/products/
我現在想從項目外的普通HTML文件調用Webapi。
我試圖做到這一點
$(document).ready(function() {
// Send an AJAX request
$.getJSON("http://localhost:31735/api/products/",
function (data) {
// On success, 'data' contains a list of products.
$.each(data, function (key, val) {
// Format the text to display.
var str = val.Name + ': $' + val.Price;
// Add a list item for the product.
$('<li/>', { html: str }).appendTo($('#products'));
});
});
});
但是這亙古不變的工作。你能幫我嗎。
非常感謝。有效。 –