使用JQuery将.php文件加载到div中 [英] Load a .php file into a div using JQuery

查看:98
本文介绍了使用JQuery将.php文件加载到div中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在搜索,没有什么适合我的需求.这是我要完成的工作:

I've been searching around and nothing quite fits what I need. Here's what I'm trying to accomplish:

<a href="">TSConfig</a> <!-- When clicked, it loads tsconfig.php which contains a form and some php code into #main_content -->
<a href="">MVSN</a> <!-- When clicked, it loads mvsn.php which contains a form and some php code into #main_content -->
<a href="">Fulfillment</a> <!-- When clicked, it loads maint_fulfil.php which contains a form and some php code into #main_content -->

<div class="grid_3" id="main_content">

    <!-- PHP CONTENT TO LOAD HERE -->

</div>

我尝试了JQuery示例的各种变体来尝试使之工作,但是大多数示例都包含从.php文件中提取ID并以某种方式处理url,这是我不想做的事情.

I have tried different variants of JQuery examples to try and make this work, however most examples contain pulling an id from with the .php file and manipulating the url somehow, which is something I didn't want to do.

非常感谢,我希望我能解释正确.

Many thanks and I hope I explained it right.

推荐答案

将您的html更改为此...

Change your html to this...

<a class="ajax-link" href="tsconfig.php">TSConfig</a> <!-- When clicked, it loads tsconfig.php which contains a form and some php code into #main_content -->
<a class="ajax-link" href="mvsn.php">MVSN</a> <!-- When clicked, it loads mvsn.php which contains a form and some php code into #main_content -->
<a class="ajax-link" href="maint_fulfil.php">Fulfillment</a> <!-- When clicked, it loads maint_fulfil.php which contains a form and some php code into #main_content -->

<div class="grid_3" id="main_content">

    <!-- PHP CONTENT TO LOAD HERE -->

</div>

这是为您加载所需页面的脚本...

and here's the script that loads the required pages for you...

$(function() {
    $("a.ajax-link").on("click", function(e) {
        e.preventDefault();
        $("#main_content").load(this.href);
    });
});

我在每个链接中添加了类ajax-link,因此您可以将上述脚本应用于它们,但不能应用于页面上的任何其他链接.

I added the class ajax-link to each of the links so you can apply the above script to them, but not any other links on the page.

这篇关于使用JQuery将.php文件加载到div中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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