Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8349783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:06:48+00:00 2026-06-09T08:06:48+00:00

I wrote a script in post.php for deleting table rows in shopping-cart. I’m sending

  • 0

I wrote a script in post.php for deleting table rows in shopping-cart. I’m sending data with jquery post to a php file. Here is my php file. I created array for outputs and i convert to json with json_encode function.

//Sepetteki Ürünleri Siliyoruz
if(isset($_POST['deleteditems']) && isset($_SESSION['userid'])) {
    $deleted_items = $_POST['deleteditems'];
   //echo $_POST['deleteditems'];
    $sql = "DELETE FROM basket WHERE productid IN ($deleted_items) AND userid = ".$_SESSION['userid'];
    //echo $sql;
    $query = mysql_query($sql);
    $basket_array['queryresult'] = ($query) ? "<i class=\"icon-ok\"></i> Silindi" : "<i class=\"icon-remove\"></i> Hata: Silinemedi";

    $basket_sql = "SELECT p.productid, p.wholesaleprice, p.minquantity, p.vat, b.quantity
                   FROM basket AS b, product AS p
                   WHERE b.productid = p.productid AND b.userid = ".$_SESSION['userid'];
    $basket_query = mysql_query($basket_sql);
    $num   = mysql_num_rows($basket_query);
    if ($num > 0) {
        while ($row = mysql_fetch_array($basket_query)) {
            $wholesaleprice = round($row['wholesaleprice']/(1+$row['vat']/100),2);
            $total_quantity = $row['quantity']*$row['minquantity'];
            $sumnovat[] = $total_quantity * $wholesaleprice;
            $vats[] = array($row['vat'], round(($row['vat']/100)* $total_quantity * $wholesaleprice,2)); // KDV'yi hesaplıyoruz
         }

     foreach ($vats as $vat) {
        $group_by_ratio_vat_sum[] = $vat[0];
     }
        $group_by_ratio_vat_sum = array_unique($group_by_ratio_vat_sum);
        $group_by_ratio_vat_sum = array_fill_keys($group_by_ratio_vat_sum,0);

     foreach ( $vats as $vat ) {
         $number = str_replace( ",", ".", $vat[1] );
         $group_by_ratio_vat_sum[ $vat[0] ] += (float)$number;
     }
        $total_vat = 0;

       $basket_array['tfoot'] = '<tr class="basket_totals"><td colspan="5" class="basketresulttitle">'._('Ara Toplam').'</td><td colspan="3">'.number_format($sumnovat = array_sum($sumnovat),2).' TL</td></tr>';

            foreach ($group_by_ratio_vat_sum as $vat_ratio => $vat_total) {
                $basket_array['tfoot'] .= "<tr class=\"basket_totals\"><td colspan=\"5\" class=\"basketresulttitle\">"._('KDV')." (%$vat_ratio)</td><td colspan=\"3\">".number_format($vat_total,2)." TL</td></tr>";
                $total_vat += $vat_total;
            }

        $basket_array['tfoot'] .= '<tr class="basket_totals"><td colspan="5" class="basketresulttitle">'._('Genel Toplam').'</td><td colspan="3">'.number_format($sumnovat + $total_vat,2).' TL</td></tr>';

        json_encode($basket_array);
    }
}

And here is my jquery code. I want to use json object in my jquery script. But i couldn’t do that. Because i’m rookie for json-jquery-php relation. Can you help me ?

$('#basket_delete_button').live('click',function(){
     var loading = '<img src="<?php echo URL; ?>images/style/loading.gif" width="16" height="16">';
     $('.loading').html(loading);
     var deleteditems = $('tbody tr input:checkbox[name="delete_basket[]"]:checked')
                                    .map(function() { return $(this).val() })
                                    .get()
                                    .join(",");

     $.post('post.php',{deleteditems: deleteditems},function(data){
          var obj = JSON.parse(data);
          $('tfoot').html(obj.tfoot);
          $("tbody tr :checked").each(function() {
               $(this).parent().parent().remove()
          });

         var rowCount = $('.basket_products_row').length;
         if (rowCount == 0){
              $('#basket_area').html("<?php echo $basket_error; ?>");
              $('#basket_count').text('0');
         } else {
              $('.loading').html(obj.queryresult);
         }
            });                               
      });

I can’t handle jquery json php relation. Can you help me ? I couldn’t manage it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:06:49+00:00Added an answer on June 9, 2026 at 8:06 am

    Try this:

    On the server-side (PHP), put a json content type header before any output is send:

    header('Content-type: application/json');
    

    and write the output:

    echo json_encode(...);
    

    On the client-side (JS), force the $.post to read JSON data:

    $.post('someurl.php', 
      {foo:'bar'},
      function(data){},
      'json'  // <--- here
    );
    

    You don’t need to use JSON.parse() here, jQuery does that for you. You can use data as an object.

    After doing the $.post() request, make a console.log(data) to debug the output. And use the browser’s debug tools to watch the ajax request output.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a simple jQuery function to submit data from a textarea. The script
I added <script type=text/javasript src=<?=base_url()?>js/jquery-1.7.2.min.js></script> in application/views/templatess/header.php and to post data to Controller using
I wrote a small PHP script to edit the site news XML file. I
I wrote a script parsing a .csv file in groovy using tokenize, which ended
I wrote this script which counts occurrences of particular pattern in a given file.
i have wrote a script to produce an array of data but now want
I wrote a PHP script. When i try to use it throws an error.
I have a PHP script that I wrote, and one of the pages connects
I wrote a PHP script to delete files selected in a gridview. This is
Hej guys, I wrote a little php script which access a database and simply

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.