我正面临着奇怪的问题。我正在实现一个SPA。我使用的是MVC,Sammy路由器,这里需要JS和Knockout。
下面是一个文件,我在其中定义了调用API的函数。
define(['jquery', 'UIBlock'], function ($) {
var GlobalParameters = function () {
this.Parameters;
this.APIEndPoint = 'http://localhost:24774/API/';
};
GlobalParameters.prototype.AjaxCallToServer = function (url, requestType, data, successCallback) {
$.blockUI();
$.ajax({
url: this.APIEndPoint + url,
data: data,
contentType: "application/json",
type: requestType,
statusCode: {
500: function () {
$('#info').html('<p>An error has occurred while processing your request.</p>');
$('#info').show();
},
409: function (xhr, ajaxOptions, thrownError) {
var message = JSON.parse(xhr.responseText).ExceptionMessage;
$('#info').html(message);
$('#info').show();
},
204: function (data) {
$('#info').html('<p>No data found.</p>');
$('#info').show();
}
},
dataType: 'json',
success: successCallback,
complete: function () {
$.unblockUI();
setTimeout(function () {
$('#info').hide();
$('#info').html("");
}, 3000);
}
});
};
return {
GlobalParameters: GlobalParameters
}
});我添加了调试器,发现它只被调用一次。
这是来自Google chrome开发人员工具的网络跟踪。

下面是每个请求的详细信息。


发布于 2016-03-02 14:20:40
这是正常的行为,它被称为预飞请求。与简单的请求不同,“预飞”请求首先将HTTP OPTIONS请求标头发送到另一个域上的资源,以便确定实际的请求是否可以安全发送
有关更多详细信息,请参阅this。
https://stackoverflow.com/questions/35739785
复制相似问题