Loading database content via XMLHttpRequest in Wordpress

谁都会走 提交于 2019-12-02 04:17:24

In wordPress, you have to use action for ajax call, something like this (basically in your functions.php)

add_action( 'wp_ajax_nopriv_myAjaxFunction', 'myAjaxFunction' );  
add_action( 'wp_ajax_myAjaxFunction', 'myAjaxFunction' );
function myAjaxFunction(){  
    //get the data from ajax call  
    $landID = $_POST['landID'];
    // rest of your code
}

Also use post instead of get something like this in you javascript file

var data = "action=myAjaxFunction&landID="+id;
xmlhttp.open("POST","http://your_site.com/wp-admin/admin-ajax.php",true);
xmlhttp.send(data);

Given example is just an idea, you should read more about it and use jQuery for ease. You can read more on Codex and here is another nice article.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!