2016-06-02 22:10 阅读 38


*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 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:

        <script src=""></script>
    点赞 评论 复制链接分享