使用javascript发布数据

时间:2014-10-11 03:52:35

标签: javascript xmlhttprequest

尝试使用javascript发布数据(当页面加载时) 生成坐标但没有别的东西,我做错了什么...... 任何帮助将不胜感激。

<p id="demo">Cords are displayed here...</p>
<script>
var x = document.getElementById("demo"); //this display the cords only to ensure script works

function getLocation() {
if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
} else { 
    x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = position.coords.latitude +" "+ position.coords.longitude; //this test if the cords are generated
lg=position.coords.latitude +" "+ position.coords.longitude;

var url = "navigator.asp"; // this page is linked to a database which saves the post
var params = "id=1&lg="+lg;
xhr.open("POST", url+"?"+params, true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
xhr.send(params);
}
</script>

0 个答案:

没有答案