使用 phpMyAdmin、jquery 通过 ajax 从服务器添加字符串

发布于 2024-10-09 00:50:01 字数 1309 浏览 0 评论 0原文

现在,我正在尝试使用 ajax 添加几个

  • 。问题是我希望这些
  • 使用服务器上数据库中的数据。我想知道该怎么做!另外,可以使用jQuery吗?
  • 假设我有一个

    ,其中有一个
      和一些
    • .这些
    • 是我想通过 ajax 更改的内容。 我使用 phpMyAdmin,其中有一个名为 t_menuMaterials 的数据库,并且我想检索 m_nom 内的字符串。 我还希望能够更改菜单,只需单击按钮即可将 t_menuMaterials 更改为 t_menuTextures。 我已经能够填充我的菜单,但只能在页面加载时这样!

    $requeteMenuMaterials = "SELECT * FROM t_menuMaterials ORDER BY m_id LIMIT 10";
    $ressourcesListe = mysql_query($requeteMenuMaterials);
    
    $targetMenu = "SELECT r_categorie FROM t_ressources ORDER BY m_id LIMIT 10";
    $ressourcesListe2 = mysql_query($targetMenu);
    $menu2 ='';
    while($tbl_ressources1 = mysql_fetch_assoc($ressourcesListe)){
        $menu2 .='<li class="secondaryMenu"><a href="#" onClick="test('.$ressourcesListe2.');" ><div>'.$tbl_ressources1['m_nom'].'</div></a></li>';
    }
    

    现在,我希望能够更改 div (就像 $requeteMenuMaterials 变为 ="SELECT * FROM t_menuTextures(而不是 t_menuMaterials))。我不知道如何使用我的数据库和 phpMyAdmin 通过 ajax 更改这些

  • Right now, i'm trying to add a couple of <li>, using ajax. The problem is that i'd like these <li> to use data from a database I have on the server. I'd like to know how to do that! Also, is it possible to use jQuery?

    Let's say I have a <div id="listHolder">, where I have a <ul> and then some <li>. Those <li> are the ones I want to change via ajax.
    I use phpMyAdmin, where I have a database called t_menuMaterials, and I want to retrieve strings inside m_nom.
    I'd also want to be able to change the menu, on a click of a button, change t_menuMaterials to t_menuTextures.
    I have been able to populate my menu, but only at the load of the page like that!

    $requeteMenuMaterials = "SELECT * FROM t_menuMaterials ORDER BY m_id LIMIT 10";
    $ressourcesListe = mysql_query($requeteMenuMaterials);
    
    $targetMenu = "SELECT r_categorie FROM t_ressources ORDER BY m_id LIMIT 10";
    $ressourcesListe2 = mysql_query($targetMenu);
    $menu2 ='';
    while($tbl_ressources1 = mysql_fetch_assoc($ressourcesListe)){
        $menu2 .='<li class="secondaryMenu"><a href="#" onClick="test('.$ressourcesListe2.');" ><div>'.$tbl_ressources1['m_nom'].'</div></a></li>';
    }
    

    Now, I'd like to be able to change the div (like if $requeteMenuMaterials became ="SELECT * FROM t_menuTextures(instead of t_menuMaterials). I have no idea on how to change those <li> via ajax using my databases and phpMyAdmin.

    如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

    评论(2

    玩套路吗 2024-10-16 00:50:01

    由于您只列出了服务端代码的一小部分,因此很难给您准确的建议。

    但一些通用的准则:

    看看 jQuery,它支持 ajax 调用,并且还有很多客户端管道更新元素。

    在服务器上,您必须对数据库的不同调用进行一些分离,以便客户端通过 URL 或 POST 数据可以告诉服务端脚本要做什么。

    Javascript 无法直接调用 php 页面的某些内部部分,您必须将页面作为常规 http 请求来调用,并使用 URL 参数或 postdata 让页面返回不同的信息。

    Its difficult to give you exact advice as you only list small parts of your service side code.

    But some general guildlines:

    Take a look on jQuery, it has support for ajax calls and also a lot of client side plumbing to update elements.

    On the server you have to have som separation of the different calls to the DB so that the client via the URL or POST data can tell the service side script what to do.

    There is no way from Javascript to directly call some inner part of a php page, you have to call the page as a regular http request and use URL arguments or postdata to have the page return different information.

    浅浅淡淡 2024-10-16 00:50:01

    jQuery $.get 可能就是您所需要的。基本上,有一个页面从数据库中提取相关数据,并将其回显到您的页面。因此,您的页面(例如 get-li-data.php)可能会输出:

    <li>An item</li>
    <li>Another item</li>
    

    并使用 $.get 获取该数据并将其插入到 div 中,例如:

    $.get('/get-li-data.php', function(data) {
      $('#div-where-i-have-a-ul').html(data);
    });
    

    jQuery $.get is probably what you need. Basically, have a page that pulls the relevant data from the database, and echo it out to your page. So your page (get-li-data.php, for example) might output:

    <li>An item</li>
    <li>Another item</li>
    

    And use $.get to get that data and insert it into a div, like:

    $.get('/get-li-data.php', function(data) {
      $('#div-where-i-have-a-ul').html(data);
    });
    
    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文