need ajax help
-
Hi guys,
i am new to wp development. below is my first plugin.
what it does is, it ads a admin panel menu, when click it will show a simple form with one text box and a submit button. the submit method is ajax.
now up to this level all ok. the problem is, i am submitting the request to another php file called update.php in my plugin folder. but in that file, update function not working in that file. it showsPHP Fatal error: Uncaught Error: Call to undefined function add_action() in /home/v72wdsfiafbt/public_html/wp-content/plugins/haf/update.php:3
Plugin page code
<?php /** * Plugin Name: haf * Plugin URI: https://www.antlerweb.xyz * Description: a plugin for huf. * Version: 1.0 * Author: antler web solutions * Author URI: https://www.antlerweb.xyz */ add_action( 'admin_menu', 'add_menu' ); function add_menu(){ add_menu_page('haf','haf','administrator','haf','haf_menu'); } function haf_menu () { echo "<div class='content'> <div id='applynow' class='apply-now'> <div class='content'> <div class='form'> <form id='recipients_form' name='recipients_form' method='' action='' > <div class='input'> <input type='text' id='number' name='number' placeholder='Enter Number' required/> <div id='res'></div> <button type='button' id='submit' class='button'> <a>Submit</a> </button> </div> </form> </div> </div> </div> </div> <script> jQuery('#submit').click(function() { var number = jQuery('#number').val(); var dataString = 'number='+ number; //alert(dataString); jQuery.ajax({ type: 'POST', url: '/wp-content/plugins/haf/update.php', data: dataString, success: function( data, textStatus, jQxhr ){ //$('#res').html( data ); //$('#contactform').trigger('reset'); alert(data); jQuery('#number').val(''); } }); return false; }); </script>"; }
update.php code
<?php add_action('init', 'process_query'); function process_query(){ $number = $_POST['number']; global $wpdb; $table_name = $wpdb->prefix . 'extra_table'; $wpdb->query("UPDATE $table_name SET number='$number' WHERE record_id=1"); echo "Record Updated."; }
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘need ajax help’ is closed to new replies.