0

我是 wp 开发插件的新手...

    <td><img class="dele" src="<?php echo plugins_url( 'images/delete.png' , __FILE__ )?> " onClick="getsize1(<?php echo $Opportunitiy->ID; ?>)"/></td>
            </tr>


  <?php } ?>
  <script type="text/javascript">
 function getsize1(id){
alert (id);
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{

if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
if(xmlhttp.responseText)
{
alert(xmlhttp.responseText);
//window.location.reload();
}
}
}


xmlhttp.open("GET","<?php echo plugins_url( 'delete.php' , __FILE__ )?>?id="+<?php echo $Opportunitiy->ID; ?>,true);
xmlhttp.send();
}

  </script>

我已经在主插件文件中这样写了..我这样调用了delete.php..

<?php 

global $wpdb;

var_dump($wpdb);
if (is_object($wpdb) && is_a($wpdb, 'wpdb')) {
echo "DELETE FROM `syn_account` WHERE ID = ".$_GET['id'];
 $sql=$wpdb->prepare("DELETE FROM `syn_account` WHERE ID = ".$_GET['id']);
 $wpdb->query($sql);


//$wpdb->delete("syn_account",  array('ID' =>$_GET['id']));
}
?>

当我打印 var_dump 时,我没有连接其他文件,它的显示错误比我得到一个空值请帮助我..

4

1 回答 1

0

why not using jquery ?

wordpress has native support for jquery and it's mych more easy then javascript.

i recommend reading om action and hooks, you can develop nothing without know them. on your specific request read here: http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in-wordpress/

good luck.

于 2013-02-12T10:21:17.513 回答