开发者

Can't get the ajax callback function to work?

开发者 https://www.devze.com 2023-03-16 16:23 出处:网络
I have the following js part to save some data and when it\'s saved ok i like to hide the form and show a succes message.

I have the following js part to save some data and when it's saved ok i like to hide the form and show a succes message.

I have this:

$.ajax({
       type: "POST",
        url: "<?php echo dirname(WP_PLUGIN_URL.'/'.plugin_basename(__FILE__)); ?>开发者_开发技巧;/save.php",
                data: str,
                success: cb_success
            });
var cb_success = function(msg){
            alert('test '+ msg);
                        if(msg == "OK") 
                        {
                            result = '<div class="notification_ok">Thank you!</div>';
                            alert('test '+ result);
                            jQuery("#widget-firn").hide();
                        }
                        else
                        {
                            result = msg;
                        }
                        jQuery(this).html(result);
                    /
                }

The first alert does show OK , but the if(msg == "OK") doesn't seem to work???


If alert(msg) returns "OK" yet msg=="OK does not work, try forcing msg toString() as it may not be that, and the reason alert does show it as one is because alert often does a toString() automatically.

So try:

msg.toString() == "OK"

If that doesn't work, then inspect what exactly msg is by using console.log(msg) for example.

0

精彩评论

暂无评论...
验证码 换一张
取 消