简体   繁体   English

为什么在动态设置 iframe 的新 src 时会收到 500(内部服务器错误)?

[英]Why am i getting 500 (Internal Server Error) when settting new src for iframe dynamically?

I have a map that indicates the current user's location..that works..but only sometimes and I don't know why.我有一张地图,指示当前用户的位置..有效..但只是有时,我不知道为什么。 I sometimes get the error "500 (Internal Server Error)" but when I visit the map.php directly then it works fine.我有时会收到错误“500(内部服务器错误)”,但是当我直接访问 map.php 时,它工作正常。

this is my HTML这是我的 HTML

<iframe  id="iframe_map" frameBorder="0"  scrolling="no" width="100%" height="200px" src=""></iframe>

this is the javascript这是javascript

$(document).ready (function(){

  //assume I have some code that gets the users current location

  //here I send the latitude and longitude as parameters to the map.php page
  //I then give my iframe a new map with new coordinates and render on HTML page

  $('#iframe_map').fadeOut(3000,function(){
    $('#iframe_map').attr('src',"map.php?lat="+position.coords.latitude+"&lon="+position.coords.longitude);            
    $('#iframe_map').fadeIn(3500);
  });
});

Try assigning values of lat and long into variables and pass this variables to the url.尝试将 lat 和 long 的值分配给变量并将此变量传递给 url。 ie IE

  $(document).ready (function(){

  //assume I have some code that gets the users current location

  //here I send the latitude and longitude as parameters to the map.php page
  //I then give my iframe a new map with new coordinates and render on HTML page
  var lat_value=position.coords.latitude;
 var long_value=position.coords.longitude;
  $('#iframe_map').fadeOut(3000,function(){
    $('#iframe_map').attr('src',"map.php?lat="+lat_value+"&lon="+long_value);            
    $('#iframe_map').fadeIn(3500);
  });
});

If the problem is not fixed try alerting the url before assigning to iframe and see if giving correct url.如果问题未解决,请尝试在分配给 iframe 之前提醒 url,并查看是否提供正确的 url。

You have to check the absolute path of src.你必须检查src的绝对路径。 Try in browser debugger in nework section.在网络部分的浏览器调试器中尝试。

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

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