Question

In: Computer Science

Web Projects If you are learning a web technology, you must create a new page that...

Web Projects If you are learning a web technology, you must create a new page that is web-accessible (use your individual burrow account) that includes a form with a field that allows the user to enter a number only.

● Create an input that allows a number to be entered. Only whole numbers should be allowed.

● Add a button below the input that says "Translate".

● When the button is clicked, it should grab the current number in the input and send a POST request to the magic number generator API with two parameters. ○ The first parameter is your team number (`team`) and can be hard-coded to your team number. ○ The second parameter is the number in your input field (`number`).

● The API returns a JSON response. You should parse the response.

● You will receive two items in the response. Display both response items in a clear way below your translate button. (Do not just display the entire JSON response.) ○ The first is a status, which will be either true (successful) or false (unsuccessful). ○ The second, if your request was successful, will be a message.

using php

Solutions

Expert Solution

I have used jquery Ajax and php for the json implementation.

json-parser.php: thisfile contains all the html form content and jquery ajax method.once user will click on the submit button , ajax function will be called whih will get json response.ajax method will parse the response and display it on html <DIV></DIV>

<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>


<!--AJAX cript -->
<script type="text/javascript">
$("document").ready(function(){
$(".js-ajax-php-json").submit(function(){
    var data = {
      "action": "test"
    };
    data = $(this).serialize() + "&" + $.param(data);
    $.ajax({
      type: "POST",
      dataType: "json",
      url: "json-api.php", //Relative or absolute path to response.php file
      data: data,
      success: function(data) {
        $(".the-return").html(
          "Status: " + data["status"] + "<br />Message: " + data["message"] + "<br />"
        );

        alert("Form submitted successfully.\nReturned json: " + data["json"]);
      }
    });
    return false;
});
});
</script>

<!--form with required fields-->
<form action="return.php" class="js-ajax-php-json" method="post" accept-charset="utf-8">
<input type="text" name="number" value="" placeholder="Number" />
<input type="text" name="team" value="" placeholder="Team Number" />

<input type="submit" name="submit" value="Submit form" />
</form>

<div class="the-return">
<!--json response will be parse here in this div-->

</div>
json-api.php: Thisfile contain whole php processing code..it will geta POST ajax call and will send json response to the json-parse.php file.this file check if its a ajax request or not ..if ajax request then it will process further.

<?php
if (is_ajax()) {
if (isset($_POST["action"]) && !empty($_POST["action"])) { //Checks if action value exists
    $action = $_POST["action"];
    switch($action) { //Switch case for value of action
      case "test": test_function(); break;
    }
}
}

//Function to check if the request is an AJAX request
function is_ajax() {
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
}

function test_function(){
$return = $_POST;

//processing post data here.
if($return["number"]!=0){
          $status = "successful";
          $message = "Your request is successfully completed";
        

   }
   else
           {
                   $status = "Failed";
           $message = "Number can not be blank!";
           }
      
        $return["status"] = $status;
        $return["message"] = $message;

//mycode


$return["json"] = json_encode($return);
echo json_encode($return);
}
?>

---------------------------------------------------

Please give me a UPVOTE. Thank you :)


Related Solutions

For this assignment you are required to create a web page displaying a recipe of your...
For this assignment you are required to create a web page displaying a recipe of your choosing. Your submission should appropriately use the basic head and body construction of an HTML document. Additionally you are required to appropriately use at least three different HTML element types. For example you might use an unordered list for your ingredients, an ordered list for the steps of your recipe, and an image to show the final result. If you choose to use an...
Create a Web Page Using HTML, CSS, JS, jQuery • Create a web profile, including any...
Create a Web Page Using HTML, CSS, JS, jQuery • Create a web profile, including any of the following: • Your hobbies, likes/dislikes, career aspirations, dream job, favorite animals/ pets, favorite superhero, etc. • You do not have to share personal information that you are uncomfortable with sharing. Follow these guidelines when creating your page: • Include at least one heading (h1, h2, etc.) in your web page. • Provide a quote from a book, movie, etc. • Include at...
In this assignment you will create a web page about your favorite sports to play or...
In this assignment you will create a web page about your favorite sports to play or teams to watch. If you don’t watch or play sports, please make up your favorite sports to play or teams to watch. You will be incorporating images into your web page, as well as other concepts learned in this unit. Create an external style sheet using a text editor of your choosing. In the CSS file add the following style rules: A background image...
You are designing a web page that allows users to create an event listing. The event...
You are designing a web page that allows users to create an event listing. The event listing should include the date, time, location, title, phone, email, coordinator, and description of the event. The location should be between 10 and 100 characters long. The title should be between 1 and 50 characters long. The description should be between 10 and 200 characters long. Phone number consists of numbers and dashes. Email has to have an @ symbol. All data elements should...
You are designing a web page that allows users to create an event listing. The event...
You are designing a web page that allows users to create an event listing. The event listing should include the date, time, location, title, phone, email, coordinator, and description of the event. The location should be between 10 and 100 characters long. The title should be between 1 and 50 characters long. The description should be between 10 and 200 characters long. Phone number consists of numbers and dashes. Email has to have an @ symbol. All data elements should...
1 -​Create the code to generate a default web page. The contents of this page should...
1 -​Create the code to generate a default web page. The contents of this page should be Your​​Name, right justified
Create a web page using PHP that allows the users to create an account (a username...
Create a web page using PHP that allows the users to create an account (a username and a password). There should be a login page that allows users to create an account by entering their preferred username and password. The same page should also let users login if they already have an account. If a user is logged in successfully , they should be able to enter a comment and also read the comments entered by others previously.
After learning the web course, write out the main steps about create a dynamic web with...
After learning the web course, write out the main steps about create a dynamic web with various different elements. kindly write main steps with various different element.
Create a web page that contains a simple math test. The page should have the following...
Create a web page that contains a simple math test. The page should have the following arithmetic problems. Add a button under each problem which, when clicked, will display a prompt for the user to enter the answer. Add a swcond button which, when clicked, will check to see if the user's answer is correct. The output should be either "correct" or "incorrect" displayed in an alert box. 1. 5+9= 2. 4*6= 3. 25-14= 4. 48/3= 5. 26%6=
For your final project, you are to create a two-page web application of your choice. ASP.NET...
For your final project, you are to create a two-page web application of your choice. ASP.NET : C# You must include the following items: At least 5 different standard server controls At least 2 validation controls At least 1 navigation control ~ one must navigate back and forth to each page One session state element Upon completion of your two-page web application, you will provide a two page report describing the functions of the web application as well as each...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT