简体   繁体   English

如何将jQuery提交的php表单GET数据回显到另一个javascript代码和URL中?

[英]How to echo a php form GET data submitted by jquery into another javascript code and URL?

I am developing an application that fetches and displays raster/image maps (png, tif), into a leaflet map. 我正在开发一个应用程序,该应用程序将栅格/图像地图(png,tif)提取并显示为传单地图。 However, I didn't like the page and the map refresh upon form submission. 但是,我不喜欢页面和地图在提交表单后刷新。

In addition, I want the map to only refresh the image layer. 另外,我希望地图仅刷新图像层。 Using the normal way, it is full of refershes. 使用常规方法,它充满了引用。 So I managed to get this code working. 因此,我设法使此代码起作用。

    $('#forms').on('submit',function(e) {
        $.ajax({
            url:'fun.php',
            data:$('#forms').serialize(),
            type:'GET',
            success:function(result){
                $('#downloads').html(result);
            }
        });
        e.preventDefault();
    });

And the leaflet image layer here. 还有这里的传单图像层。

raster = L.imageOverlay('<?php echo $datafile;?>', [[33.00, 31.00], [43.50, 35.00]]);  

So the exact problem is, the $datafile couldn't be echoed on leaflet raster layer and I would like to reset the form values after submit. 所以确切的问题是,$ datafile无法在小叶栅格图层上回显,我想在提交后重置表单值。 I tried to use setUrl from leaflet method on image layer but it doesn't work. 我试图在图像层的传单方法中使用setUrl,但它不起作用。

Thank you for the help! 感谢您的帮助!

The problem is solved. 问题已经解决了。 First, I changed echo $datafile to echo '<script type="text/javascript">imageUrl = "'. $datafile. '"; </script>'; 首先,我将echo $datafile更改为echo '<script type="text/javascript">imageUrl = "'. $datafile. '"; </script>'; echo '<script type="text/javascript">imageUrl = "'. $datafile. '"; </script>'; This js variable is echoed in the html output page. 该js变量在html输出页面中回显。 Then, it was possible to call the js variable, imageUrl. 然后,可以调用js变量imageUrl。

There, was another problem with the image display. 在那里,图像显示还有另一个问题。 I was hiding the image layer div using display:none when no file is found. 没有找到文件时,我使用display:none隐藏了图像层div。 That cause the image not to show. 这导致图像无法显示。 Thus, in the jquery success function, I had to add, $("img.leaflet-image-layer.leaflet-zoom-animated").show(); 因此,在jquery成功函数中,我必须添加$("img.leaflet-image-layer.leaflet-zoom-animated").show();

Then a friend helped me to add a function using setUrl() function of leaflet which is used to change the imageUrl asynchronously. 然后,一个朋友帮助我使用了传单的setUrl()函数添加了一个函数,该函数用于异步更改imageUrl。

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

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