سؤال

I am building up an app and if I don't use virtual pages accessing data from a local or remote database, the app will become heavy. So the question is what script should I use in HTML5 to access the data from the DB every time there is a search query?

Thanks in advance.

هل كانت مفيدة؟

المحلول

Without more details about what kind of remote database or data you are trying to use it is hard to propose a solution.

In general for remote databases I like to use Parse.com APIs and find them very responsive.

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);
  }
});

For more information please see: https://parse.com/docs/js_guide#queries

If you are set on using php, you could echo the javascript inside php. I'm sure this isn't the most idea way to use php, however it should work.

<?php
    echo "
        <script type=\"text/javascript\">
        //place javascript here
        </script>
         "
?>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top