0
您好我是jquery mobile和web api的新手,我目前正在使用這兩個項目。我在IIS7中託管了應用程序,我無法訪問我的控制器,當我嘗試這樣做時,我總是遇到404錯誤。在我的開發機器上,它工作正常。我看過一些關於堆在他們的非流動問題的答案似乎是working.Any幫助PLZ如何解決託管網絡api上的404錯誤
見下面的代碼
WebApiConfig.cs
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
我控制器
public class ManufacturerController : ApiController
{
private List<Manufacturer> manufacturers = new List<Manufacturer>();
public ManufacturerController()
{
manufacturers.Add(new Manufacturer(1, "AUDI"));
manufacturers.Add(new Manufacturer(2, "BMW"));
manufacturers.Add(new Manufacturer(3, "MAZDA"));
manufacturers.Add(new Manufacturer(4, "NISSAN"));
manufacturers.Add(new Manufacturer(5, "FORD"));
}
public IEnumerable<Manufacturer> GetManufacturers(string manufacturerSearch)
{
var _products = manufacturers.Where(p => p.Name.Contains(manufacturerSearch.ToUpper()));
return _products;
}
我的jquery手機自動完成代碼
(document).on("pageinit", function() {
//manufacturer search
$("#manufacturer").on("listviewbeforefilter", function (e, data) {
var $ul = $(this),
$input = $(data.input),
value = $input.val(),
html = "";
$ul.html("");
if (value && value.length > 0) {
$ul.listview("refresh");
$.ajax({
beforeSend: function() {
$ul.html('<h4>Loading...</h4>');
},
url: "http://my_server/api/manufacturer/?manufacturerSearch=" + value,
//timeout: 3000,
dataType: "jsonp",
crossDomain: true,
data: {
q: $input.val()
},
error: function (xhr, errorType) {
//if (errorType === "error") {
//showError(xhr.status, xhr.statusText);
//$input.val("");
alert("Error: " + xhr.status + "," + xhr.statusText);
//}
}
})
.then(function (response) {
$.each(response, function (i, val) {
html += "<li id='" + val.Id + "'>" + val.Name + "</li>";
});
$ul.html(html);
$ul.listview("refresh");
$ul.trigger("updatelayout");
$ul.find('li').on("click", function() {
$input.val($(this).text());
selectedManufacturerId = getId(this);
$("#manufacturer").empty();
});
});
}
});
在此先感謝