Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.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
使用JQuery html()时,它会在使用Ajax之前返回内容_Jquery_Ajax - Fatal编程技术网

使用JQuery html()时,它会在使用Ajax之前返回内容

使用JQuery html()时,它会在使用Ajax之前返回内容,jquery,ajax,Jquery,Ajax,我有一个div来保存文章内容,它可以通过ajax进行更改 我需要这个div中的内容,我使用jquery函数html()来实现这一点,但它只能在更改之前获取内容 如何使用jquery获取即时内容 更新: 它在我自己的页面上运行得很好,问题是来自其他网站的“分享到facebook”按钮脚本 这是一个示例脚本: <script type="text/javascript" charset="utf-8"> (function(){ var _w = 72 , _h = 16;

我有一个div来保存文章内容,它可以通过ajax进行更改

我需要这个div中的内容,我使用jquery函数html()来实现这一点,但它只能在更改之前获取内容

如何使用jquery获取即时内容

更新:

它在我自己的页面上运行得很好,问题是来自其他网站的“分享到facebook”按钮脚本

这是一个示例脚本:

  <script type="text/javascript" charset="utf-8">
(function(){
  var _w = 72 , _h = 16;
  var param = {
    url:'dachaocai.com/bench/2',
    type:'3',
    count:'1', 
    appkey:'', 
    title:$('#title').html()+'(Bench->'+$('#b_name').html()+')'+'http://www.dachaocai.com/bench/2', 
    pic:'', 
    ralateUid:'', 
    rnd:new Date().valueOf()
  }
  var temp = [];
  for( var p in param ){
    temp.push(p + '=' + encodeURIComponent( param[p] || '' ) )
  }
  document.write('<iframe allowTransparency="true" frameborder="0" scrolling="no" src="http://hits.sinajs.cn/A1/weiboshare.html?' + temp.join('&') + '" width="'+ _w+'" height="'+_h+'"></iframe>')
})()
</script>

(功能(){
var _w=72,_h=16;
变量参数={
网址:'dachaocai.com/bench/2',
类型:'3',
计数:'1',
appkey:“”,
标题:$('#title').html()+'(Bench->'+$('#b#u name').html()+')'+'http://www.dachaocai.com/bench/2', 
图:'',
ralateUid:“”,
rnd:新日期()。valueOf()的值
}
var-temp=[];
for(参数中的var p){
温度推送(p+'='+encodeURIComponent(参数[p]| |''))
}
文件。写入(“”)
})()
我使用html()获取文章标题以供共享,但它始终是旧标题。
有什么办法可以解决这个问题吗?

您可以使用Jquery对服务器进行异步调用,然后在回调中向div追加一些Html。我希望这能有所帮助。如果你发布一些代码,我可以更新答案

<div id="div">

</div>
编辑: 创建一个div以将结果放入:

<div id='result'></div>

var url = "http://hits.sinajs.cn/A1/weiboshare.html?' + temp.join('&');
$.get(url, function(data){
    $('#result').html(data);
});

变量url=”http://hits.sinajs.cn/A1/weiboshare.html?'+临时连接('&');
$.get(url、函数(数据){
$('#result').html(数据);
});
通过这种方式,您可以从服务器获取html,而不必像iframe那样复杂。
然后您可以从div读取数据

set缓存:false

$.ajax({
  url: "test.html",
  cache: false,
  success: function(html){
    $("#results").append(html);
  }
});

您可能需要将
.html
放在ajax回调中。您可以显示一些代码吗?请发布您的代码,或者更好的是,设置一个提琴:这些答案有帮助吗?很抱歉我反应太晚。:)您的答案确实有帮助。
$.ajax({
  url: "test.html",
  cache: false,
  success: function(html){
    $("#results").append(html);
  }
});