2017-04-21 38 views
0

當我單擊按鈕時,我有上面的JSON錯誤。它不返回任何值。可以請你幫我解決這個問題,parsererror SyntaxError:JSON.parse:JSON數據第1行JSON數據後的JSON數據後的意外非空白字符

這裏我jQuery代碼,

$(document).ready(function(){ 
    $('.package_details').click(function(){ 

    $('.txt-form').slideDown("slow"); 
    var package = $(this).attr("id"); 

    $.ajax({ 
     type:"post", 
     url:"aaa.php", 
     dataType: 'json', 
     data:"pack="+pack, 
     success:function(html){ 

     $('.package_name').val(html.package_name); 
     $('.package_price').val(html.package_price); 

     $('.discount_percentage').val(html.discount); 
     $('.amount_after_discount').val(html.amnt_discount); 
     $('.tax_percentage').val(html.tax); 
     $('.amount_after_tax').val(html.amnt_tax); 

     if(html.package_type == 'Contact Visible'){ 
      $('.contact').attr('checked', 'checked'); 
     }else if(html.package_type == 'Job post'){ 
      $('.job').attr('checked', 'checked'); 
     }else if(html.package_type == 'Both'){ 
      $('.both').attr('checked', 'checked'); 
     } 

     $('.contact_visible').val(html.count); 
     $('.job_post').val(html.job_post); 
     $('.valitity_day').val(html.valitity); 
     }, 
    error: function (jqXHR, textStatus, errorThrown) { 
     alert('Not done - ' + textStatus + ' ' + errorThrown); 
    } 
    }) 
    }) 
}) 

,在這裏我的PHP代碼,

echo json_encode(array("package_name"=>$package_name,"package_type"=>$package_type,"discount"=>$discount,"amnt_discount"=>$amnt_discount,"tax"=>$tax,"amnt_tax"=>$amnt_tax,"count"=>$count,"job_post"=>$job_post,"package_price"=>$package_price,"valitity"=>$valitity)); 
+0

你不是以json格式發送數據 – ManiMuthuPandi

+0

它純粹在過去工作,但現在它返回錯誤 –

+0

是否有任何問題,我的代碼 –

回答

0

創建JSON變量像下面然後發佈該數據字段

post_data = { "pack": pack}; 

$.ajax({ 
     type:"post", 
     url:"aaa.php", 
     dataType: 'json', 
     data:post_data, 
. 
. 
. 
+0

我試過根據你的代碼。但是現在仍然有同樣的錯誤。 –

相關問題