Put the AJAX command inside a function called startAjax() or whatever, and call this function when the page loads. You can then just type startAjax() within the button's onclick attribute. The javascript section should look like this:
<script type='text/javascript'>
//AJAX function
function startAjax() {
$.ajax({
type: "POST",
url: "test.php",
data: "name=name&location=location",
success: function(msg){
alert( "Data Saved: " + msg );
}
});
}
//Call AJAX:
$(document).ready(startAjax);
</script>
And the button:
<button onclick="startAjax();">Test</button>
Hope this helps. :)