wordpress - WP ajax always returns 0 even when using die -


I am trying to use AJAX in WP mode and I can not get back any feedback. If I manually use AJAX and include the url in a php file then it works fine but I want to use AJAX in "proper" way in wp.

What do I have here

  add_action ('wp_ajax_get_data', 'get_data'); Function get_data () {$ group = $ _GET ['option_group']; $ Data_table = 'tablename'; $ BigArray = array () to capture // array data; // variable for determining select clause $ query = "SELECT * $ data_table WHERE group = $ group"; $ Datas = $ wpdb- & gt; Get_results ($ query); Forex currency ($ data as $ data) {array_push ($ bigArray, $ data); Echo json_encode ($ bigArray); // Always do not forget to exit the AJAX function. Die (); }  

then request

  jQuery ('# new_service #service_option_group'). ('Change', function () {// Ajax query to get results: jQuery.ajax ({type: 'GET', url: ajaxurl, data: {action: 'get_data', data: jQuery ('# Service_option_group '). Serialize ()}, success: function (result) {jQuery (' #new_service #service_option_region '). Empty option to add empty option (default) in var option = document.createElement (' option ') Required; var select = document.getElementById ('service_option_region'); option.text = 'Select an option' option.value = -1; select.appendChild (option); // (var i = 0; i & Attribute events for lt; result.length; i ++) {// Create and add each element to Var Option = document.createElement ('option'); option.text = resu liter [i] .title; option.value = result [i] .id; var select = document.getElementById ('service_option_region'); select.appendChild ( Option);}}, error: function (request, condition, error) {warning (request.responseText);}})});  


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -