最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why Angular AJAX request is visible twice in chrome network tab - Stack Overflow

programmeradmin1浏览0评论

I just noticed that when I made Angular (1.4.8) AJAX POST request it is visible twice in chrome network tab (first (355B) as angular.js:10765 and second (812B) as other where first looks like request and second as response - only second contains response data). I made identical request by use of jQuery and it's appearing as a single request (812B).

CODE:

return function ( id ) {
  var deferred = $q.defer()
    , data = {
      id: id || null,
      range: tbDateRange.get( true )
    }
    ;

  /* TODO - REMOVE */
  $.ajax({
    method: 'POST',
    url: path,
    dataType: 'JSON',
    data: data
  });

  $http.post( path, data )
    .success( function ( data ) {
      /*...*/
      deferred.resolve( data );
    } )
    .error( function ( error ) {
      /*...*/
    } );
  return deferred.promise;
};

And network tab screenshot:

I just noticed that when I made Angular (1.4.8) AJAX POST request it is visible twice in chrome network tab (first (355B) as angular.js:10765 and second (812B) as other where first looks like request and second as response - only second contains response data). I made identical request by use of jQuery and it's appearing as a single request (812B).

CODE:

return function ( id ) {
  var deferred = $q.defer()
    , data = {
      id: id || null,
      range: tbDateRange.get( true )
    }
    ;

  /* TODO - REMOVE */
  $.ajax({
    method: 'POST',
    url: path,
    dataType: 'JSON',
    data: data
  });

  $http.post( path, data )
    .success( function ( data ) {
      /*...*/
      deferred.resolve( data );
    } )
    .error( function ( error ) {
      /*...*/
    } );
  return deferred.promise;
};

And network tab screenshot:

Share Improve this question edited Jan 7, 2016 at 14:56 LJ Wadowski asked Jan 7, 2016 at 10:22 LJ WadowskiLJ Wadowski 6,72811 gold badges48 silver badges77 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

Angular defaults to POSTing JSON formatted data instead of form encoded data (jQuery does not so the statement I made identical request by use of jQuery is incorrect).

Cross-origin, JSON formatted, POST requests require a preflight OPTIONS request.

Presumably (because you haven't show any details of the requests besides the end of the URL they are going to), the first of those requests is that preflight OPTIONS request.

发布评论

评论列表(0)

  1. 暂无评论