i am trying to send this json data to my controller but its not going can you please check it out for me? thanks in advance
// this is my script in form filefunction verifyTransactionOnBackend(transactionId) { // console.log("Verifying transaction on backend, transaction ID:", transactionId); const postData = { transaction_id: transactionId, store_id: document.getElementById("store_id").value, plan_id: document.getElementById("plan_id").value, start_date: document.getElementById("start_date").value, end_date: document.getElementById("end_date").value, status: 'active', price: document.getElementById("price").value, }; $.ajax({ method: "POST", url: "<?php echo admin_url('membership/insert_user_payment')?>", data: postData, // No need to stringify if contentType is not set to "application/json" dataType: "json", success: function(response) { console.log("Server response:", response); if (response.status && response.status === 'success') { window.location.href = "<?php echo admin_url('welcome'); ?>"; } else { console.error("Error in response:", response.msg || "Undefined error message"); document.querySelector("#payment-failed").style.display = 'block'; } }, error: function(xhr, status, error) { console.error("Error:", error); document.querySelector("#payment-failed").style.display = 'block'; } });}
// this is my controller public function insert_user_payment() { $postData = json_decode($this->input->raw_input_stream, true); // Prepare the data for insertion $insert_data = ['transaction_id' => $postData['transaction_id'],'tore_id' => $postData['store_id'],'plan_id' => $postData['plan_id'],'tart_date' => $postData['start_date'],'end_date' => $postData['end_date'],'tatus' => $postData['status'],'price' => $postData['price'] ]; var_dump($postData); $insert = $this->db->insert('membership_payments', $insert_data); // Check if the insert was successful if ($insert) { echo json_encode(['status' => 'uccess', 'sg' => 'Payment recorded successfully.']); } else { echo json_encode(['status' => 'error', 'sg' => 'Failed to record payment.']); }}