Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php ie和jquery$。无法工作_Php_Javascript_Jquery_Ajax - Fatal编程技术网

Php ie和jquery$。无法工作

Php ie和jquery$。无法工作,php,javascript,jquery,ajax,Php,Javascript,Jquery,Ajax,我试图用$更新div的内容。get调用,但在ie(9)中失败。 js就是这样 function UpdateElementOfParent(box_id, page_ref, template_ref) { $.get("get_content.php", { box_id: box_id, page_ref: page_ref, template_ref:template_ref } ) .done(function(data) {

我试图用
$更新div的内容。get
调用,但在
ie(9)中失败。

js
就是这样

function UpdateElementOfParent(box_id, page_ref, template_ref)
{
 $.get("get_content.php", { box_id: box_id, page_ref: page_ref, template_ref:template_ref } )
  .done(function(data) {                  
         $('#'+box_id).html(data);              
      });  
}
  <?php   
include("connect.php"); 
$page_ref = $_GET['page_ref'];  
$template_ref = $_GET['template_ref'];
$box_id = $_GET['box_id'];  
$sql = mysql_query("SELECT * FROM site_content WHERE page_ref='$page_ref' AND template_ref='$template_ref' AND box_id='$box_id' AND box_type='text'");
while($row=mysql_fetch_array($sql))  
    {  
      echo stripslashes($row['content']);  
    }  
   ?> 
下面是
get_content.php

function UpdateElementOfParent(box_id, page_ref, template_ref)
{
 $.get("get_content.php", { box_id: box_id, page_ref: page_ref, template_ref:template_ref } )
  .done(function(data) {                  
         $('#'+box_id).html(data);              
      });  
}
  <?php   
include("connect.php"); 
$page_ref = $_GET['page_ref'];  
$template_ref = $_GET['template_ref'];
$box_id = $_GET['box_id'];  
$sql = mysql_query("SELECT * FROM site_content WHERE page_ref='$page_ref' AND template_ref='$template_ref' AND box_id='$box_id' AND box_type='text'");
while($row=mysql_fetch_array($sql))  
    {  
      echo stripslashes($row['content']);  
    }  
   ?> 

警报数据没有在IE中显示更新的文本,因此它肯定与$有关。get call

这不是答案,因为问题不完整,但我需要发布代码注释以帮助操作

正如您提到的,PHP工作正常,问题可能是IE不喜欢jQuery中的动态选择器。请尝试以下几个选项:

1) 更改
$('#'+box_id).html(数据)至:

var id = '#'+box_id;
$(id).html(data);
2) 尝试记录或警告删除元素,以查看IE是否确实正确地获取了元素:

var elem = $('#'+box_id);
alert(elem);
elem.html(data);
如果元素存在,则显示为
[htmldevelment]
或类似内容

3) 如果所有这些都失败了,那么看看这个香草JS是否在IE中工作,以验证它不是一个jQuery选择器问题

var elem = document.getElementById(box_id);
alert(elem);
elem.innerHTML = data;

我解决了这个问题。与选择器无关,但与参数变量
box\u id
的范围有关

将您的功能更改为:

function UpdateElementOfParent(box_id, page_ref, template_ref) {

    myBox = box_id;
    $.get("get_content.php", { box_id: box_id, page_ref: page_ref, template_ref:template_ref })
        .done(function(data) {                  
             $('#'+myBox).html(data);              
        });  
}
说明:


AJAX回调函数无法访问
UpdateElementOfParent

中的局部变量。问题解决了,我知道这是非常明显的

在最初的$.get函数调用中,我必须设置document.ready状态

function get_edit_content(box_id,page_ref,template_ref)
  {
    $(document).ready(function() { <<<<<HERE   
        if(area1) {     
           area1.removeInstance('edit_content');
           area1 = null;
           document.getElementById("edit_content").value="";         
         }
        $.get("get_content.php", { box_id: box_id, page_ref: page_ref, template_ref:template_ref } )
        .done(function(data) {       
           document.getElementById("edit_content").value=data;         
           document.getElementById("page_ref").value=page_ref;
           document.getElementById("template_ref").value=template_ref;          
           document.getElementById("box_id").value = box_id;                     
           area1 = new nicEditor({fullPanel : true}).panelInstance("edit_content",{hasPanel : true});             
         });  
    });
函数获取编辑内容(框id、页面参考、模板参考)
{

$(document).ready(function(){尝试从第5行删除
,然后6@Imperative
.get
可以处理任何类型的数据。他的PHP不会返回JSON。请尝试在
$('#'+box_id).html(数据);
警报(数据)之前添加
警报('Ok');
);
@silentw该引用建议添加分号,而不是将其省略。请尝试innerHTML,参见我的帖子