javascript - Ajax not returning success result in Wordpress -


I am trying to get the updated value from the database. I used one of the WordPress plugins folder to send AJAX data to the function inside a function. I tried to be cautious on both success and unsuccessful functions, and it has always implemented the failed function. How do I know if the AJAX response is successful so that I can make some extra code when I succeed?

SCRIPT

  Remove function subfolders (department, user) {var value = {user_id: user, dep_name: department.id}; $ ('#' + Department.id + user + "_ div"). hide (); $ Ajax ({type: "post", data: value}); }   

function.php

  Remove function user () {if (isset ($ _ POST ['user_id'])) {// resonant $ _POST [ 'User ID']; // resonant $ _POST ['dep_name']; $ User_meta = get_user_meta ($ _ POST ['user_id'], 'wpwf_quotation_position'); $ User_department = json_decode ($ user_meta [0]); // print_r ($ user_department); // resonance (json_encode ($ user_department)); Foreign currency ($ user_department $ key = & gt; $ value) {if ($ value == strtolower ($ _ POST ['dep_name'])) {// print_r ($ user_department); Not set ($ user_department [$ key]); $ User_department = array_values ​​($ user_department); // print_r ($ user_department); // resonance (json_encode ($ user_department)); // print_r (json_encode ($ user_department)); Update_user_meta ($ _POST ['user_id'], 'wpwf_quotation_position', json_encode ($ user_department)); break; } // echo $ key ":". $ Value "-" strtolower ($ _post ['dep_name']). "& lt; br & gt;"; } // resonance 'ssss'; wp_send_json ($ _post); }} Add_action ('init', 'removeUser');   

The code above runs well, but what I really want to do is down, but the work of success is not called. Am I missing here or did it wrong?

  Remove function subfolders (department, user) {var value = {user_id: user, dep_name: department.id}; $ .jax ({type: "post", data: value, success: work () {$ ('#' + department.id + user + "_ div"). Hide ();}}); }    

You use your browser console to debug this kind of thing At the moment I can say that you are not a 'undefined function' error which means that it can not recognize $ $, instead use securemed jQuery (jQuery.ajax).

In addition to this you were also remembering the URL to work with your AJAX call.

  Remove the function subpage (department, user) {var value = {action: 'removeUser' / * assuming this is your alex verb / /, user_id: user, dep_name: department.id}; JQuery.ajax ({type: "post", url: "/wp-admin/admin-ajax.php", data: value, success: function (output) {console.log (output); / / your output.other_id Look at the console to find your values ​​like jQuery ('#' + department.id + user + "_ div") hide ();}}}}}   

Besides, I can not see that you have also applied the php function to wp_ajax. I agree that you have done this?

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -