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.
加载中,请稍侯......
精彩评论