dongyou1926 2016-06-02 22:10
浏览 38
已采纳

使用Javascript,我可以“读取”页面上的h2类并检索和显示与该值相关的数据[关闭]

*not looking for code to be provided, just want to know if its possible.

For example. I have an h2 class named "stock-number" and its value is #NC123456. Can javascript read each instance of that class, fetch data from another database using that value, and display the results in another class.

Real world example would be if I sold TVs. The TV has an msrp and inventory is retrieved from one database. However, we can set a sale price. and the discounts and rebates are from another database, sorted by that tvs stock number.

Can I read that stock number, pull the pricing break down from the other database, and display in back into the page underneath the sale price in its own div so customers understand their savings?

  • 写回答

1条回答 默认 最新

  • douzhenggui8171 2016-06-02 22:17
    关注

    Yes, it can.

    In order to do the database lookup, receive the returned data, and update the DOM with new data, you also need to use AJAX.

    Basic ajax tutorial

    You might also want to compare jQuery code to the above pure javascript code -- most folks find jQuery a lot faster/easier (especially with AJAX).

    jQuery is a library that runs on top of javascript and all that is required in order to use it is to include the library somewhere on the page:

    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
    </head>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分