ajax不会成功

ajax不会成功,ajax,Ajax,我正在尝试从我的webapi服务器获取数据。调试节目 GET http://localhost:62578/api/DB [HTTP/1.1 200 OK 2ms] 但是我没有点击success,而是点击error,没有数据被传递到error函数 var records; var loadedData = new Array(); $.ajax({ type: 'GET', dataType: 'json', accept: "application/json",

我正在尝试从我的webapi服务器获取数据。调试节目

GET http://localhost:62578/api/DB [HTTP/1.1 200 OK 2ms]
但是我没有点击success,而是点击error,没有数据被传递到error函数

var records;
var loadedData = new Array();

$.ajax({
    type: 'GET',
    dataType: 'json',  
    accept: "application/json",
    url: 'http://localhost:62578/api/DB',
    //data: { a:'a' },
   // contentType: 'application/json; charset=utf-8',
    success: function(data) {
    //I never get here.
        $.each(data, function (key, val) {//key is the row number, val is the  object data below
                $.each(val, function (key2, val2) {//key2 is the array element name, val2 is the data. 
                    if (key == 0) loadedData.push(key2);  //we only need one row of collumns
                });
                records = key;
                init(loadedData);   
                });
            },
             error: function(jqXHR, exception) {
            //both return undefined.
        }
        });
webapi服务器日志

jttp=http FYI(愚蠢的堆栈溢出)


我认为您的javascript代码位于不同的端口上;也许端口80和json请求位于端口62578。Ajax请求只允许在相同的域、协议和端口中进行

为了解决问题,您需要使用JSONP数据类型或任何其他类似机制(服务器端解决方案)

签出以获取有关JSONP的更多信息

检查如何将JSONP与jQueryAjax调用结合使用


查看类似问题。

您使用的是localhost还是它只是一个示例
localhost:62578/api/DB
?请确保添加
http://
jqXHR.status为0,jqXHR.responseText未定义,exception为undefinedStackoverflow一直在唠叨如何将http放入我的帖子中,它不允许我继续使用http“\\n在那里。好了,http现在在那里:)thx friend!而且我现在看到了不同的输出,不确定我没有做任何改变。虽然仍然没有帮助----jqXHR.status为0,jqXHR.responseText为“”,异常为“error”啊ok abood1,我跟着你们。
iisexpress.exe Information: 0 : Request, Method=GET, Url=jttp://localhost:62578/api/DB, Message='jttp://localhost:62578/api/DB'
iisexpress.exe Information: 0 : Message='DB', Operation=DefaultHttpControllerSelector.SelectController
iisexpress.exe Information: 0 : Message='MvcApplication1.Controllers.DBController', Operation=DefaultHttpControllerActivator.Create
iisexpress.exe Information: 0 : Message='MvcApplication1.Controllers.DBController', Operation=HttpControllerDescriptor.CreateController
iisexpress.exe Information: 0 : Message='Selected action 'GetAllProducts()'', Operation=ApiControllerActionSelector.SelectAction
iisexpress.exe Information: 0 : Operation=HttpActionBinding.ExecuteBindingAsync
iisexpress.exe Information: 0 : Message='Action returned 'MvcApplication1.Models.DataBase[]'', Operation=ReflectedHttpActionDescriptor.ExecuteAsync
iisexpress.exe Information: 0 : Message='Will use same 'JsonMediaTypeFormatter' formatter', Operation=JsonMediaTypeFormatter.GetPerRequestFormatterInstance
iisexpress.exe Information: 0 : Message='Selected formatter='JsonMediaTypeFormatter', content-type='application/json; charset=utf-8'', Operation=DefaultContentNegotiator.Negotiate
iisexpress.exe Information: 0 : Operation=ApiControllerActionInvoker.InvokeActionAsync, Status=200 (OK)
iisexpress.exe Information: 0 : Operation=DBController.ExecuteAsync, Status=200 (OK)
iisexpress.exe Information: 0 : Response, Status=200 (OK), Method=GET, Url=jttp://localhost:62578/api/DB, Message='Content-type='application/json; charset=utf-8', content-length=unknown'
iisexpress.exe Information: 0 : Operation=JsonMediaTypeFormatter.WriteToStreamAsync
iisexpress.exe Information: 0 : Operation=DBController.Dispose