Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Signup form After the user leaves the email field, check against the database to

ID: 3560453 • Letter: S

Question

Signup form After the user leaves the email field, check against the database to see if the email is already registered to an existing account. If it is, display an appropriate error message on the page (without refreshing the page). Post details page When a user submits the comment form, add the new comment to the comments section (without refreshing the page). The comment form should return to a blank state after the form is submitted. Responses from the server side should be provided in the form of valid JSON objects. All JavaScript event processing should be registered using the DOM 2 method. Grading Scheme This assignment will be graded out of 6 marks, based on the following criteria: Back-end coding to support AJAX requests. Properly formatted JSON objects holding the updated data. Front-end coding to produce AJAX requests.

Explanation / Answer

Back-end coding to support AJAX requests

// Some functions that work with a database.
include "suggestions.lib.php";
// Get the query result.
$query = $_REQUEST["query"];
$result = get_suggestions($query);
// Give a name to the first element of result.
$result["first"] = $result[0];
$GLOBALS['_RESULT'] = $result; // $_RESULT will be passed to frontend

Properly formatted JSON objects holding the updated data

if (Integer.parseInt(res) == 1) {
   pDialog.setMessage("Loading User Space");
   pDialog.setTitle("Getting Data");
   DatabaseHandler db = new DatabaseHandler(getApplicationContext());
   JSONObject json_user = json.getJSONObject("user");
   /**
   * Clear all previous data in SQlite database.
   **/
   UserFunctions logout = new UserFunctions();
   logout.logoutUser(getApplicationContext());
   db.addUser(json_user.getString(userFirstName), json_user.getString(userLastName), json_user.getString(userEmail));
   /**
   *If JSON array details are stored in SQlite it launches the User Panel.
   **/
   Intent upanel = new Intent(getApplicationContext(), MainActivity.class);
   upanel.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
   pDialog.dismiss();
   startActivity(upanel);
   /**
   * Close Login Screen
   **/
   finish();
logout user:

public boolean logoutUser(Context context){
   DatabaseHandler db = new DatabaseHandler(context);
   db.resetTables();
   return true;
   }

adduser:

public void addUser(String userFirstName, String userLastName, String userEmail) {
   SQLiteDatabase db = this.getWritableDatabase();

   ContentValues values = new ContentValues();
   values.put(KEY_FIRSTNAME, userFirstName); // FirstName
   values.put(KEY_LASTNAME, userLastName); // LastName
   values.put(KEY_EMAIL, userEmail); // Email


Front-end coding to produce AJAX requests

   // Inserting Row
   db.insert(TABLE_LOGIN, null, values);
   db.close(); // Closing database connection
   }

// Send a query.
JsHttpRequest.query(
  "/ajax/suggester", // backend address
  { query: search_string.value }, // parameters
  function(result, errors) {
   // This function will be called when result is ready.
   // Suggest the most popular word as query.
   autocomplete_query(result["first"]["name"]);
   // Draw "suggestions" to query.
   show_suggestions (result);
  }
);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote