Home ajax not adding data to database
Reply: 0

ajax not adding data to database

user2045
1#
user2045 Published in June 20, 2018, 1:31 am

I'm trying to send the array selectedItems to my database using ajax but for some reason this isn't working for me.

Every time I click on the button that calls to deposit() I first get alert:

"Thank you, We will send you a trade request as soon as possible!"

but then i get the alert:

"something went wrong, please try again."

because $_POST["setDeposit"] isn't set.

Javascript:

function deposit() {
    var selectedItems = ["Banana", "Orange", "Apple"];
    if (selectedItems.length !== 0) {
        $.ajax({
            type: "POST",
            url: 'http://csgodonut.com/home/depositdone',
            data:{setDeposit:selectedItems},
            success:function() {
                alert("Thank you, We will send you a trade request as soon as possible!");
            }
        });
    } else {
        alert("Please select atleast one item.");
    }
}

Controller:

public function depositdone() {
    if(isset($_POST['setDeposit'])) {
        $array = $_POST['setDeposit'];
        $depositItems = implode("<>", $array);
        $steamid = $steamprofile["steamid"];

        $tradeurl = $this->home_model->get_trade_url($steamid);

        if ($tradeurl !== NULL) {
            $this->home_model->add_deposit($tradeurl, $steamid, $depositItems);
            header("Location:/home");
        } else {
            echo '<script>alert("You don\'t have a Tradelink set, please click on your name to set it!");</script>';
            header("Location:/home");
        }
    } else {
        echo "<script>
        if (confirm('something went wrong, please try again.')) {
            window.location.replace('http://csgodonut.com/home');
        } else {
            window.location.replace('http://csgodonut.com/home');
        }
        </script>";
    }
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.319115 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO