Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7783297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:47:47+00:00 2026-06-01T19:47:47+00:00

My solution is using onClick event to call a PHP page, post parameters and

  • 0

My solution is using onClick event to call a PHP page, post parameters and return result using AJAX. I insert parameter right at time calling PHP page using specified URL.
Here is my Javascript:

function uploadContact() {
        var name, email, phone, badgeid;
        if(window.localStorage.length > 0)
        {
            name = window.localStorage.getItem('name');
            email = window.localStorage.getItem('email');
            phone = window.localStorage.getItem('phone');
        }
        else
        {
            name = $('input[name=fullname]').val();
            email = $('input[name=email]').val();
            phone = $('input[name=phone]').val();
        }
        $.ajax({
             url: 'UpdateContactList.php?name=' + name + '&email=' + email + '&phone=' + phone,
             type: $form.attr('method'),
             dataType: 'json',
             success: function(responseJson) {
             $form.before("<p>"+responseJson.message+"</p>");
        },
        error: function() {
            $form.before("<p>There was an error processing your request.</p>");
        }});
    }

My PHP code to get parameters:

<?php

$response = array();

if($_SERVER['REQUEST_METHOD'] == 'POST')
{
  // if form has been posted process data

  // you dont need the addContact function you jsut need to put it in a new array
  // and it doesnt make sense in this context so jsut do it here
  // then used json_decode and json_decode to read/save your json in
  // saveContact()
   $data = array( 'fullname' => $_POST['name'], 'email' => $_POST['email'], 'phone' => $_POST['phone']);
      //These line is for testing only, remove it when done testing
   $test = $_POST['name'] . ' ' . $_POST['email'];
   echo "<script>alert('$test');</script>";
  // always return true if you save the contact data ok or false if it fails
   $response['status'] = updateContact($data) ? 'success' : 'error';
   $response['message'] = $response['status']
          ? 'Your submission has been saved!'
          : 'There was a problem saving your submission.';

   header("Content-type: application/json");
   echo json_encode($response);
   exit;
}
...
 function updateCacheFile($filename)
{
    $filename = "contact";
    $filename =  $filename . ".appcache";
    $cachefile = fopen ($filename, "a+");
    ....
    file_put_contents($filename, $cache_content);
}

Please notice 2 problems:

  1. I can call directly PHP page with parameters from browse address link, do this will return nothing. Is it normally?

  2. Call from javascript. The testing line (call an alert message box) won’t work, no message appeared. But the cache file still updated, which means PHP page is called and do things like writing files.

There is 2 files to be written in this PHP page. Both of them were written correctly but the parameters won’t show up and no message box show.

Please instruct me what went wrong here.

P/S: small detail, Is parameter with space can be pass correctly? Because I expected users input their full name, such as ‘Bill Jobs’.

Thanks to Stackoverflow community.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:47:49+00:00Added an answer on June 1, 2026 at 7:47 pm
       echo "<script>alert('$test');</script>";
      // always return true if you save the contact data ok or false if it fails
       $response['status'] = updateContact($data) ? 'success' : 'error';
       $response['message'] = $response['status']
              ? 'Your submission has been saved!'
              : 'There was a problem saving your submission.';
    
       header("Content-type: application/json");
       echo json_encode($response);
    

    All headers must be executed before you begin echoing or otherwise flushing output.

       header("Content-type: application/json");
       echo "<script>alert('$test');</script>";
      // always return true if you save the contact data ok or false if it fails
       $response['status'] = updateContact($data) ? 'success' : 'error';
       $response['message'] = $response['status']
              ? 'Your submission has been saved!'
              : 'There was a problem saving your submission.';
    
       echo json_encode($response);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using an asp.net fileupload string in an Server Side onClick event. ASP.Net file upload
I had a working solution using ASP.NET MVC Preview 3 (was upgraded from a
I have a VS2008 solution using xml documentation, and we have warnings as errors
I am using Sourcesafe 2005 in a 3-project solution using Visual Studio 2008. The
I want to implement the solution using the pre-processor described here: Reuse define statement
I'm looking for a simple solution using Python to store data as a flat
My application is a client/server solution using an ADO.NET Data Service. The Data Service
I'm trying to implement a solution using .htaccess and wildcard subdomains so that http://subdomain.example.com
I am trying to use a COMET solution using ASP.NET . Trouble is I
I want to find a programmatic solution using C++. I have a 900 files

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.