从jquery转换为angularjs时,为什么会出现此错误?

问题描述:

jQuery代码从jquery转换为angularjs时,为什么会出现此错误?

$.ajax({ 
     url: '/ad_creation/get_campaign_objective/'+id, 
     dataType: 'text', 
     success: function(response) { 
      var campaign_objective = 'Error. Please refresh and try again.'; 
      if (response == 'WEBSITE_CONVERSIONS') 
       campaign_objective = response; 
      if (response == 'WEBSITE_CLICKS') 
       campaign_objective = response; 

      $('select[name=campaign_objective]').val(response).hide(); 
      $('#existing-campaign-objective').html(campaign_objective).show(); 
      $('#campaign-objective-select').show(); 

      if (campaign_objective == 'WEBSITE_CONVERSIONS'){ 
       // Show pixel block again. 
       $('#select-pixel').show(); 
      } 
      hideAjaxLoader('existing-campaign-loader'); 
     }, 
      error: function(xhr, ajaxOptions, thrownError) { 
       console.log('Invalid response', thrownError, xhr, ajaxOptions); 
       hideAjaxLoader('existing-campaign-loader'); 
     } 
    }); 

Angularjs代码

$http({ 
     method:'get', 
     dataType:'text', 
     url:'/ad_creation/get_campaign_objective/'+Number(id) 
    }) 
    .success(function(data){ 
     console.log(data); 
    }) 

我得到错误的意外标记W上。我也试过不把数字转换成数字,但仍然出现错误。

检查响应标题的content-type
如果它是'application/json'angular试图解析响应。
错误可能是因为它。