简体   繁体   中英

wordpress plugin to pass data from jquery to php then save to database

I am new to this topic. I tried with the following example

created a plugin folder in plugins folder "abc-referer"

created a php file name with "abc-referer.php" and entered following php code

abc-referer.php

wp_enqueue_script( 'ajax-script', plugins_url( '/my_query.js', __FILE__ ), array('jquery') );

wp_localize_script( 'ajax-script', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'we_value' => 1234 ) );

In the same folder i created a jquery file named "my_query.js" and entered following code

$.post( "referer.php", { name: "John", time: "2pm" })
  .done(function( data ) {
    alert( "Data Loaded: " + data );
  });

});

In the same folder i created a file named with "referer.php" to get values posted from jquery,

echo $POST['name'] . ' at ' . $POST['time'];
//save to database functionality.

I don't know where i did mistake. my_query.js is loading correctly. Please give me correction on this to work perfect.

I try to do the same staff, bro. But correct path is far away from your try. The easiest way is http://uzx.com/wp-contents/plugins /abc-referer/referer.php or what domain you bought. But this solution is not proffesional at all and do not allow to give it to commercial purpose. use this code url('<?php echo plugin_dir_url( __FILE__ ). "ulica.jpg"; ?>') or src='<?php echo plugin_dir_url( __FILE__ ). "ulica.jpg"; ?>' ) url('<?php echo plugin_dir_url( __FILE__ ). "ulica.jpg"; ?>') or src='<?php echo plugin_dir_url( __FILE__ ). "ulica.jpg"; ?>' ) url('<?php echo plugin_dir_url( __FILE__ ). "ulica.jpg"; ?>') or src='<?php echo plugin_dir_url( __FILE__ ). "ulica.jpg"; ?>' ) look at detail '' || "" '' || "" make big differ because of its power. ' ' is stronger and take everything as it is written. What's more, you should avoid situation like using ' ' more then once due to the fact it close the code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM