简体   繁体   English

是否可以使用JS发送值而无需刷新地图表单?

[英]Is it possible to send a value using js without map form refresh?

I have implemented search by map function on my web-site. 我已经在网站上实现了按地图搜索功能。 The map have some divisions that are clickable and send a value to the controller. 该地图具有一些可单击的划分,并将一个值发送给控制器。

<form name="myform" action="index.php?option=com&amp;task=seacrh_by_map" method="post">
<dd id="imgDI">
<a id="DI" href="javascript:getvalue('DI')" 
</a>
</dd>
<dd id="imgDII">
<a id="DI" href="javascript:getvalue('DII')" 
</a>
</dd>
<input type="hidden" name="my_value" value="" />    
</form>


<script language="JavaScript" type="text/javascript">
<!--
function getvalue (my_value)
{
document.myform.my_value.value = my_value;
document.myform.submit() ;
}
-->
</script>

After sending this form, the controller gives an answer (results of search) and the map returns to its original position. 发送此表格后,控制器给出答案(搜索结果),地图返回到其原始位置。 Is there a way to prevent that? 有办法防止这种情况吗? The map should show the division that was chosen. 地图应显示所选的分区。 Is there a way to send a value to controller using js without map form refresh? 有没有一种方法可以使用js在不刷新地图表单的情况下将值发送到控制器?

You can use AJAX and JSON for this 您可以为此使用AJAX和JSON

AJAX = a method of retrieving resources asynchronously via HTTP using JavaScript AJAX =一种使用JavaScript通过HTTP异步检索资源的方法

JSON = stands for JavaScript Object Notation JSON =代表JavaScript对象符号

Simple Example is Here 简单的例子在这里



AJAX stands for asynchronous JavaScript and XML, a scary-sounding mix of technologies, but don't let the buzzwords scare you. AJAX代表异步JavaScript和XML,这是一种听起来很吓人的技术组合,但是请不要用流行语来吓you您。 Think of AJAX as a programming technique that combines several technologies. 将AJAX视为结合了多种技术的编程技术。 And remember, you're in luck because jQuery simplifies AJAX for you. 记住,您很幸运,因为jQuery为您简化了AJAX

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM