Javascript 不带提交按钮的call post方法导致无限循环
我有一个表格,我想从中的纬度和经度,我想加载这个没有提交按钮Javascript 不带提交按钮的call post方法导致无限循环,javascript,php,html,dom,Javascript,Php,Html,Dom,我有一个表格,我想从中的纬度和经度,我想加载这个没有提交按钮 <form method="post" id="myform" action="" > <input type='hidden' value='' name='latitude'/> <input type='hidden' value='' name='longitude'/> </form> 但它会导致无限循环,我希望它在同一页上,所以我不会给出动作 我添加了这个函数,但仍
<form method="post" id="myform" action="" >
<input type='hidden' value='' name='latitude'/>
<input type='hidden' value='' name='longitude'/>
</form>
但它会导致无限循环,我希望它在同一页上,所以我不会给出动作
我添加了这个函数,但仍然不起作用
function send_data(lat, lon) {
document.getElementById('place_lon').innerHTML = lat + ' : ' + lon;
// $("input[name='lattitude']").val(lat);
// $("input[name='longitude']").val(lon);
$j = jQuery.noConflict();
$j(document).ready(function() {
$j('#myform').submit(submit_myform);
});
function submit_myform() {
$j.ajax({
url: window.location.href,
type: 'POST',
data: $j(this).serialize(),
dataType: 'json', //data type of Ajax response expected from server
success: myform_success //callback to handle Ajax response and submit to Paypal
});
return false;//prevent normal browser submission, since the form is submitted in the callback
}
function myform_success(response) {
//this is called whenever the ajax request returns a "200 Ok" http header
//manipulate the form as you wish
$("input[name='latitude']").val(lat);
$("input[name='longitude']").val(lon);
// $j('#lattitude').val(lat);
// $j('#longitude').val(lon);
//submit the form (to the form's action attribute)
document.forms['#myform'].submit();
}
}
所发生的情况是,一旦加载表单,它就会提交自己,然后再次加载并提交,等等 尝试使用AJAX请求将数据发送到服务器
$.ajax({
type: "POST",
url: window.location.href,
data: $('#myForm').serialize()
});
您什么时候执行提交?可能您的页面一直在无限地向自己提交。尝试在document.getElementById(“myForm”).submit()上添加一些条件;在加载我的表单时…我应该使用哪种类型的条件…我尝试了这一点,并将其添加到我的脚本代码中。我不太了解AJAX,但我仍然没有在$\u POST[“纬度”]和$\u POST[“经度”]中获得任何值。。
$.ajax({
type: "POST",
url: window.location.href,
data: $('#myForm').serialize()
});