0

I'm learning to use mysqli and AJAX and building a simple application using AJAX to insert data into a database and display data in a table from the database. The table should display current information at the time that the webpage is loaded and then update anytime a record is added to the database using the HTML form. I'm having a couple ofissues.

  1. Thus far, the form works from my main HTML file, except that it leaves the page and opens addActorInfo.php, instead of just refreshing the main page.
  2. I have the table working when I open the getActorInfo.php file in a browser, but it is not being pulled into the main page.

Any suggestions would be appreciated.

EDIT INFORMATION: I solved problem number 1 and have updated the HTML code to reflect changes. Currently, I believe I have a bug somewhere in my drawTable() function that is preventing the table produced by the PHP GET FILE from being returned back to the main page. I've tried using the statement "document.getElementById("actor_display").innerHTML=xmlhttp.responseText;", but it's still not showing up.

Main HTML

3
  • 3
    While you're learning PHP MySQL connection stuff, you should just drop mysql(i) entirely and use PDO Commented Feb 18, 2013 at 5:44
  • The mysqli is working fine. It's the AJAX that I'm having trouble with. I added an event handler to the form and that solved the problem of the webpage leaving the main page. However, my attempts to use AJAX and JavaScript to take the table built by the GET file and place it below the form haven't worked out. Commented Feb 18, 2013 at 5:56
  • You should still drop the mysqli. PDO is much better, if I could only say one good thing that pdo has and mysqli doesn't prepared statements net.tutsplus.com/tutorials/php/… Commented Feb 19, 2013 at 22:43

1 Answer 1

1

Why not use jQuery on the ajax?

var data = $('#yourdatainsertionform');
$.ajax({
  data:data,
  method:'POST', //Or get
  url:'yourphp.php',
  success:function(result){
    $('#actor_display').html(result);
  },
  error:function(){
    alert("Something went wrong");
});

By using jQuery, you would make your life easier. No more hair ripping moments with IE, and so easy ajax requests & form validation. Basically, what you can do with javascript, you do it easier with jQuery.

The usage is so simple, just include

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

on your page before loading the files you will be using jQuery.

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.