我正在构建一个应用程序,如果我不使用从本地或远程数据库访问数据的虚拟页面,该应用程序将变得沉重。那么问题是,每当有搜索查询时,我应该在HTML5中使用什么脚本来访问数据库?
提前致谢。
答案 0 :(得分:0)
如果没有关于您尝试使用哪种远程数据库或数据的更多详细信息,很难提出解决方案。
一般来说,对于远程数据库,我喜欢使用Parse.com API并发现它们非常敏感。
Parse.initialize("YOUR KEY GOES HERE"); //API key
//whatever you want to call your storage object
var jobApplicant = Parse.Object.extend("JobApplicant");
//create new instance of your Parse Object
var jobApplicant = new JobApplicant();
//you can add each param separately and save
jobApplicant.set("jobid", "1234");
jobApplicant.set("name", "john smith");
jobApplicant.set("position", "manager");
jobApplicant.set("years experience", "5");
jobApplicant.set("status", "rejected");
jobApplicant.save();
//or use object literal notation
jobApplicant.save({jobid: "1236", name: "ashley jones",
position: "software engineer",
years experience: "15",
status: "accepted offer"
}).then(function(object) {
alert("Job Applicant Recorded!");
});
//query
var NewHire = Parse.Object.extend("NewHire");
var query = new Parse.Query(NewHire);
query.equalTo("status", "accepted offer");
query.find({
success: function(results) {
alert("Successfully retrieved " + results.length + " candidates.");
// Do something with the returned Parse.Object values
for (var i = 0; i < results.length; i++) {
var object = results[i];
alert(object.id + ' - ' + object.get('name'));
}
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});
有关详细信息,请参阅:https://parse.com/docs/js_guide#queries
如果你开始使用php,你可以回复php里面的javascript。我确信这不是最常用的使用php的方法,但它应该可以工作。
<?php
echo "
<script type=\"text/javascript\">
//place javascript here
</script>
"
?>