将 .php 页面加载到 div Ajax 和 Javascript 中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11498306/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 13:25:40  来源:igfitidea点击:

Load .php page into a div Ajax and Javascript

phpjavascriptajax

提问by dabious

(I am pretty new to all this.) I have a page where the user can click between different sorting methods of user posts. Depending on which they click the content shown will correspond.

(我对这一切都很陌生。)我有一个页面,用户可以在其中单击用户帖子的不同排序方法。根据他们单击的内容,显示的内容将对应。

function newContent()
{
  $.ajax({
      url: 'ajax/newcontent.php',
      success: function() 
      {
            $("#content_div").empty().load("ajax/newcontent.php");
      }

      });
}

This is what I have now. But instead of loading the code from the .php page into the #content_box, the #content_box just goes blank.

这就是我现在所拥有的。但不是将 .php 页面中的代码加载到 #content_box 中,#content_box 只是变为空白。

Any help would be awesome!

任何帮助都是极好的!

EDIT ** changed #content_dov to #content_div - whoops

编辑 ** 将 #content_dov 更改为 #content_div - 哎呀

回答by Joyce Babu

Why are you using two ajax requests? You just need to use

为什么要使用两个ajax请求?你只需要使用

$("#content_dov").load("ajax/newcontent.php");

The full code is

完整的代码是

function newContent()
{
    $("#content_dov").load("ajax/newcontent.php");
}

回答by Raab

function newContent()
{
  $.ajax({
      url: 'ajax/newcontent.php',
      success: function(data) 
      {
            $("#content_dov").html(data);
      }

      });
}