2015-02-24 100 views
0

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上。我也試過不把數字轉換成數字,但仍然出現錯誤。

回答

0

檢查響應標題的content-type
如果它是'application/json'angular試圖解析響應。
錯誤可能是因爲它。

相關問題