1

I'm new to ajax and would like to use it with php to create a table that a user can edit in the front end of the webapp.

this is what i have so far...

PHP

class genTable{

  public function table1(){

    global $data;
    $result = $data->getData(); //from another class
    echo '<table class="table"> 
            <tbody>
              <tr>
                <td>Heading</td>
              </tr>';

    foreach($result as $res){
      echo '<tr><td>' . $res['Name'] . '</td></tr>';
    }
    echo '</tbody></table>';
  }

}

eventually i will just call that function to display it, is there a way to create a jquery function that uses ajax to add on three buttons update, edit and new that carry out their actions?

2
  • Two things, back-end & front-end. What you are doing is a back-end code generating front-end. You'll use Jquery AJAX on front-end, and need to make a call to a PHP page (back-end) that throw some data to AJAX handle and display it at current front-end. Start here: api.jquery.com/jQuery.ajax Commented Dec 6, 2013 at 9:54
  • This is an open-ended question. Try sharing some code you've cooked up yourself. Additionally, you can look at Editable DataTables using jquery to implement desired functionality. Commented Dec 6, 2013 at 9:54

1 Answer 1

1

What I would do in such case is

foreach($result as $res){

    echo '<tr>'
    echo '<td>' . $res['Name'] . '</td>';
    echo '<td><a href="#" onclick="UpdateUser('.$res['Name'].')">Update</a></td>';
    echo '<td><a href="#" onclick="EditUser('.$res['Name'].')">Edit</a></td>';
    echo '<td><a href="#" onclick="NewUser()">New</a></td>';
    echo '</tr>';

}

Then I'd write those JavaScript functions which will receive $res['Name'] (or ID ?) as parameter.

Those functions can then make ajax call when invoked for next action.

Sign up to request clarification or add additional context in comments.

Comments

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.