Note that there are some explanatory texts on larger screens.

plurals
  1. POpassing class method's argument via ajax
    text
    copied!<p>A generic add record function in database.inc.php</p> <pre><code>public function insert($data, $table) { $columns = ""; $values = ""; foreach ($data as $column =&gt;$value) { $columns .= ($columns == "") ? "" : ", "; $columns .= $column; $values .= ($values == "") ? "" : ", "; $values .= $value; } $sql = "insert into $table ($columns) values ($values)"; mysql_query($sql) or die(mysql_error()); //return the ID of the user in the database. return mysql_insert_id(); } </code></pre> <p>Method to Add category :</p> <pre><code>&lt;?php include './database.inc.php'; class Categories{ public function AddCategory(){ $db = new Database(); $b-&gt;connect(); $db-&gt;insert($data, $table); } } ?&gt; </code></pre> <p>In the insert method the $data is the $_POST array. This function is working fine but i want to pass the $_POST array not by php but by ajax jquery. I will find out how to get post array in jquery but my question here is how will i make an ajax call to this specific insert method in categories class as there will be more methods in categories class like delete , update, etc etc... I've heard that in asp.net there is an option that they pass the page name as well as the method name in the URL: parameter of jquery ajax.</p> <p>Updated: This is how i am calling the method: page : categories.php class : categories.inc.php;</p> <pre><code> &lt;?php if (isset($_POST['submit'])) { unset($_POST['submit']); $_POST['DateAdded']; $_POST['DateAdded']=date("Y-m-d"); // print_r($_POST); $Connection = new Database(); $Connection-&gt;Connect(); $Category = new Categories(); $Category-&gt;AddCategory($_POST,"categories"); } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload