जवाबों:
"सुरक्षित और क्लीनर" तरीका एडमिन-ajax.php का उपयोग करना होगा wp_ajaxजो आपके प्लगइन फ़ाइल से आपके प्रोसेसिंग फ़ंक्शन को कॉल करने के लिए वर्डप्रेस और हुक के साथ आता है और कॉल की अखंडता की जांच करने के लिए wp-nonce का उपयोग करता है।
उदाहरण के लिए:
आपका अजाक्स JQuery कॉल होगा
<script type="text/javascript" >
jQuery(document).ready(function($) {
var data = {
action: 'ACTION_NAME',
Whatever: '1234',
_ajax_nonce: '<?php echo wp_create_nonce( 'my_ajax_nonce' ); ?>'
};
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
// If you need it on a public facing page, uncomment the following line:
// var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
jQuery.post(ajaxurl, data, function(response) {
alert('Got this from the server: ' + response);
});
});
</script>
फिर अपने प्लगइन फ़ाइल में जोड़ें
//if you want only logged in users to access this function use this hook
add_action('wp_ajax_ACTION_NAME', 'my_AJAX_processing_function');
//if you want none logged in users to access this function use this hook
add_action('wp_ajax_nopriv_ACTION_NAME', 'my_AJAX_processing_function');
* यदि आप ajax द्वारा अपने फ़ंक्शन को एक्सेस करने के लिए उपयोगकर्ताओं और मेहमानों में लॉग इन करना चाहते हैं तो दोनों हुक जोड़ें। * ACTION_NAME को आपके ajax POST में कार्रवाई मूल्य से मेल खाना चाहिए।
तब आपके फ़ंक्शन में यह सुनिश्चित करें कि अनुरोध मान्य स्रोत से आया है
function my_AJAX_processing_function(){
check_ajax_referer('my_ajax_nonce');
//do stuff here...
}
उम्मीद है की यह मदद करेगा