插入php代码后地图页面变为空白 [英] map page becomes blank after inserting php code

查看:93
本文介绍了插入php代码后地图页面变为空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将php代码插入infowindow内容后,我的gmap页面变为空白。

  google.maps.event.addListener(noi ,'mouseover',function(){
var infowindow = new google.maps.InfoWindow({
content:'<?php
if($ count == 0){
echoNo Open Tickets;
}
else {
echo< table>;
foreach($ NOIcompliancearray as $ SLA_Compliance => $ count){
$ Npath = $ Nimages [$ SLA_Compliance];
echo< tr>;
echo< td>< a href ='city.php?city = Noida& $ SLA_Compliance。'>< / td>;
echo< img src ='IndiaImages /\".$ Npath。'title ='。 < td>。$ count。< / td>;
echo< / tr>;
}
echo< / table>;
}
?>'
size:new google.maps.Size(100,100),
});
go ogle.maps.event.addListener(noi,'mouseover',function(){
infowindow.open(map,noi);
setTimeout(function(){infowindow.close(map,noi)},5000);
});

如果我用一些静态内容替换php代码,它可以正常工作。另外,当我尝试打开网页源代码时,它给了我想要在信息窗口中看到的结果。我不知道我在哪里犯了错误。



从网页源代码输出:
内容:



 '< table>< tr>< td>< a href ='city.php?city = Noida& compliance = A'>< img src ='IndiaImages / Circle_Red.gif'title ='A'>< / td>< td> 3< / td>< / tr>< tr>< td>< a href ='city.php?city = Noida& compliance = C'>< img src ='IndiaImages / Circle_Yellow.gif'title ='C'>< / td>< td> 10< / td>< / tr>< / table> ; Noida' 



请帮助我理解错误并减轻问题。

解决方案

code> google.maps.event.addListener(noi,'mouseover',function(){
var infowindow = new google。 maps.InfoWindow({
content:'...'
size:new google.maps.Size(100,100),
});

用php获得

  google.maps.event.addListener(noi,'mouseover',function(){
var infowindow = new google.maps.InfoWindow({
content:'< table> ;
< tr>
< td>< a href ='
//'city.php?city = ......'在内容之后:字符串结尾符号````会被函数忽略!
size:new google.maps.Size(100,100),
});

php 生成的第一个'将被解释为字符串的结尾
其余的将在html源代码中,你可以看到它,但被函数忽略。

所以不要使用'

  echo< td>< a href ='city。 php?city = Noida& compliance =。$ SLA_Compliance。'> 

转义标志而不是

  echo< td>< a href = \\city.php?city = Noida& ompliance = \。$ SLA_Compliance。\>

转义 看看这里


My gmap page turns blank after inserting php code into the infowindow content.

google.maps.event.addListener(noi, 'mouseover', function() {
  var infowindow = new google.maps.InfoWindow({
    content: '<?php 
        if ($count==0){
        echo "No Open Tickets";
        }
    else{
        echo "<table>";
        foreach ($NOIcompliancearray as $SLA_Compliance=>$count) {
            $Npath = $Nimages[$SLA_Compliance];
            echo "<tr>";
            echo "<td><a href='city.php?city=Noida&compliance=".$SLA_Compliance."'><img src='IndiaImages/".$Npath."' title='".$SLA_Compliance."' ></td>";
            echo "<td>".$count."</td>";
            echo "</tr>";
            }
        echo "</table>";        
    }
  ?>'
    size: new google.maps.Size(100,100),
  });
google.maps.event.addListener(noi, 'mouseover', function() {
infowindow.open(map,noi);
setTimeout(function() { infowindow.close(map, noi) }, 5000);
});

If i replace php code with some static content it works fine. Also, when I tried opening the webpage source code, it gives me result which i wanted to see in the info window. I am not sure where I am making mistake.

output from the webpage source code: content:

'<table><tr><td><a href='city.php?city=Noida&compliance=A'><img src='IndiaImages/Circle_Red.gif' title='A' ></td><td>3</td></tr><tr><td><a href='city.php?city=Noida&compliance=C'><img src='IndiaImages/Circle_Yellow.gif' title='C' ></td><td>10</td></tr></table>Noida'

Kindly help me understand the mistake and to mitigate the problem.

解决方案

Look at the function

google.maps.event.addListener(noi, 'mouseover', function() {
  var infowindow = new google.maps.InfoWindow({
    content: '...'
    size: new google.maps.Size(100,100),
  });

with php you get

google.maps.event.addListener(noi, 'mouseover', function() {
  var infowindow = new google.maps.InfoWindow({
    content: '<table>
            <tr>
            <td><a href='
   // 'city.php?city=......' is after content : string ending sign `'` will be ignored by function !
    size: new google.maps.Size(100,100),
  });

The first ' generated by php will interpreted as end of the string the rest will be in html source. you can see it but ignored by the function.

So don't use ' in that kind of code.

echo "<td><a href='city.php?city=Noida&compliance=".$SLA_Compliance."'>

escape the " sign instead

echo "<td><a href=\"city.php?city=Noida&ompliance=\"".$SLA_Compliance."\">"

escape " look here

这篇关于插入php代码后地图页面变为空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆