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.
精彩评论