admin管理员组文章数量:1392094
I am trying fetch WordPress user data from an external page within same domain using ajax.The problem is i am getting errors which contain the user data and source code from one of my plugin.
here is my code
external_page.php
<?php
require './wp-load.php';
$type=isset($_POST["type"]);
if ($type=="showlist")
{ //here data is fetched from wordpress database
foreach ( $users as $info )
{
$response = [$info->user_login => $info->user_email];
}
echo json_encode($response);
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href=".4.1/css/bootstrap.min.css">
</head>
<body>
<button id="recover" name="recover" class="btn btn-info" onclick="loadadmin()"><span class="glyphicon glyphicon-search"></span> recover account</button>
<script src=".4.1/jquery.min.js"></script>
<script src=".js/1.16.0/umd/popper.min.js"></script>
<script src=".4.1/js/bootstrap.min.js"></script>
<script>
function loadadmin() {
$.ajax({
url:'external_page.php',
method:'POST',
data:{
type:'showlist' },
dataType:'json',
success:function(response) {
alert('success');
},
error:function(xhr, textStatus, errorThrown){
alert("error msg :"+ xhr.responseText);
}
});
}
</script>
</body>
</html>
here is the code of my plugin
sample_plugin.php
<?php
/**
Plugin headers
**/
function global_session_value()
{
echo "
<script type=\"text/javascript\">
sessionStorage.setItem(\"lastname\", \"Smith\");
</script>";
}
add_action( 'shutdown', 'global_session_value');
?>
<script type="text/javascript" >
var global_value=<?php echo has_action('shutdown');?>;
</script>
I am getting following ajax error response message from my external page
error msg:
//code from sample_plugin.php
<script type="text/javascript" >
var global_value=1;
</script>
{"user1":"[email protected]"}//this the ajax response
//code from sample_plugin.php
<script type="text/javascript">
sessionStorage.setItem("lastname", "Smith");
</script>
I get success alert when i disable the plugin "sample_plugin"
. How to solve this problem so that i can get the success response without disabling the plugin?
本文标签: pluginsErrors while using ajax from external wordpress page
版权声明:本文标题:plugins - Errors while using ajax from external wordpress page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744780152a2624659.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论