0

When I click button I have above JSON error. It doesn't return any values. can you please help me to solve this,

Here my Jquery code,

$(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);
    }
    })
  })
})

And Here my PHP code,

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));
5
  • You are not sending data in json format Commented Apr 21, 2017 at 6:26
  • It purely worked in past but now it return error Commented Apr 21, 2017 at 6:28
  • Is there any issues for my code Commented Apr 21, 2017 at 6:30
  • see what is there in html by using console.log(html) in success function Commented Apr 21, 2017 at 6:32
  • these are all textbox values when ajax function go to the success handler that values may replaces json values Commented Apr 21, 2017 at 6:36

1 Answer 1

0

Create json variable like below then post this in data field

post_data =  {  "pack": pack};

$.ajax({
      type:"post",
      url:"aaa.php", 
      dataType: 'json',
      data:post_data,
.
.
.
Sign up to request clarification or add additional context in comments.

1 Comment

I tried as per your code. But still now i got same error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.