开发者

How to hit the database on the function?

I have a quesion can I hit the database on my view?

I have function like this..

  function ShowHIPAATab(url) {

            if ($("#BxFlag").val() == "1") {
                $("#bv-1").attr('src', url);
            } else {
                return false;
            }
        };

on this funcation I need to hit the database to get the BXFlag value.how to do 开发者_如何学Cthat?


use jquerys ajax

http://api.jquery.com/jQuery.ajax/


So this being javascript it is running in the browser not the server, so you don't have direct access to the database. Depending on your situation there a couple ways you can get this value:

  • If the value is known at the time that you render the page then you can set a javascript variable with the value in your view. This has the advantage of being simple and not requiring an additional call to the server.
  • If the value can not be known until after you render, or if it can change during the lifetime of the page then use jquery AJAX as gov points out.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜