Monday 15 April 2013

How to invoke PHP file in AJAX/JavaScript? -


I have this code that receives php file using an AJAX method. The goal is to inform the user that the film table is empty or if the table is empty, it will display a confirmation box that will ask if the user wants to add movies or not?

Here is my index.php file:

  & lt; A href = "#" onclick = "checkmovitable ('../ajaxphp / moviestbl.php')" title = "movie" & gt; Film & lt; / A & gt;   

Here is my moviestbl.php:

  & lt ;? Includes php ('../phpfunc/connect'); // contains the connection to mysql $ checkMovieTable = mysql_query ("Sections ASC by the movies ORDER") or die ("not found table"); $ CountRows = mysql_num_rows ($ checkMovieTable); If ($ countRows == 0) {? & Gt; & Lt; Script language = "javascript" & gt; Var option = Confirm ("no movie found? Now add movies?"); If (option == true) {// redirect to another page window. Location = "../addmedia.php?add=movies"; } And {// do nothing} return to the current window} & lt; / Script & gt; & Lt ;? Php}? & Gt;   

And finally, here's my AJAX file

    

When I click on the link, it does not do anything or is not helping need help. Thank you.

You must obtain data from server using an AJAX request, the response may be in JSON format

Tip

  1. Use jQuery and $ .ajax to pull data from server
  2. upon receipt of the response - Confirm and switch window

    You can construct arguments to handle specific logic in the client & amp; Server:

    • PHP: There may be logic on the server and the interface to answer with the JSON result for the status of entries on the movie table can be. Your current query should work fine.

    • Javascript: Use the defined interface on php to query the data and use 'confirmation' javascript to switch. / P>

      If you change now

        & lt; A href = "#" onclick = "Czech Movietable ('../Ajaxphp / moviestbl.php')" title = "movie" & gt; Film & lt; / A & gt; & Lt; A href = "/ ajaxphp / moviestbl.php" title = "movies" & gt; Film & lt; / A & gt;   

      You should work with this page reload and redirect.

No comments:

Post a Comment