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 7740627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:49:43+00:00 2026-06-01T08:49:43+00:00

I am trying to post data from PHP to Server which is built in

  • 0

I am trying to post data from PHP to Server which is built in java using jquery.It responding with json.
Following PHP , Jquery post code

    <script  type="text/javascript" charset="utf-8">

    $(function() {
        // wire up the buttons to dismiss the modal when shown
    $("#dialog-form").bind("show", function() {
        $("#dialog-form #add-ques").click(function(e) {
            // do something based on which button was clicked
            // we just log the contents of the link element for demo purposes
            $.post('question_data.php', $("form#gform").serialize(), function(data) {


                             if(data.result=="true"){
                                     //window.location=+data.lastId;
                                    console.log(data);

                                 }else{

                                     $("#dialog-form").modal('hide');

                                 }

                         },"json");

            // hide the dialog box
            $("#dialog-form").modal('hide');

        });

    }); 

</script>

This modal form which send the data to server

<div id="dialog-form" class="modal hide fade">
        <div class="modal-header">
            <a class="close" data-dismiss="modal">×</a>
            <h3>Add Question</h3>
        </div>
        <div class="modal-body">
            <form  id=gform  >

                <div class="control-group" class="form-horizontal">
                        <label class="control-label" for="question">Write Your Question</label>
                        <div class="controls">
                            <input type="text" class="span3" id="question"
                                name="question" placeholder="Enter Survey Question">
                                <input type="hidden" value=save id="type" name="type" />
                                <input type="hidden" value=12 id="survey_id" name="survey_id" />

                        </div>
                    </div>

                <hr/>
                <label for="name">Write Options</label> 
                            <div class="controls">
                 <input type="text" name="option1"  id="option1"  placeholder="Option 1" />
                <input type="text" name="option2"   id="option2"  placeholder="Option 2" />
                        </div>

                            <div class="controls">
                <input type="text" name="option3"   id="option3" placeholder="Option 3" />
                <input type="text" name="option4"   id="option4" placeholder="Option 4"  />
                        </div>










            </form>

        </div>
        <div class="modal-footer">
            <a href="#" class="btn"  data-dismiss="modal" >Close</a> <a href="#" id="add-ques" class="btn btn-primary">Save
                changes</a>
        </div>

    </div>

This is PHP code which takes the Posted data and send to server and return JSON
//question_data.php

    if($type=="save"){
    $type= htmlspecialchars(trim($_REQUEST["type"]));
$question= htmlspecialchars(trim($_POST["question"]));
$survey_id= htmlspecialchars(trim($_POST["survey_id"]));
$opt1= htmlspecialchars(trim($_POST["option1"]));
$opt2= htmlspecialchars(trim($_POST["option2"]));
$opt3= htmlspecialchars(trim($_POST["option3"]));
$opt4= htmlspecialchars(trim($_POST["option4"]));


$result = json_decode(file_get_contents("http://mobsurvey.jelastic.servint.net/question/new/?question=$question&survey_id=$survey_id&option1=$opt1&option2=$opt2&option3=$opt3&option4=$opt4"));
$arr = array('result' => $result->result, 'lastId' => $result->lastId);

    header('Content-type: text/json');
    header('Content-type: application/json');

    echo json_encode($arr);

}

JSON O/P

    {"result": "true","lastId": 86}

Sometime above code runs WELL But sometime returns null.Unable to track this problem

  • 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-01T08:49:45+00:00Added an answer on June 1, 2026 at 8:49 am
    //Track it on the server side
    
    if($type=="save"){
            $surveyname= htmlspecialchars(trim($_POST["name"]));
            $company_id= htmlspecialchars(trim($_POST["company_id"]));
            $flag = 1;
            if($surveyname == null || $surveyname == ""){
              $flag = 0;
            }
            if($company_id == null || $company_id == ""){
              $flag = 0;
            }
    
        if($flag){
            $result = json_decode(file_get_contents("http://localhost:8080/mobsurvey/survey/new/?name=$surveyname&company_id=$company_id"));
            $arr = array('result' => $result->result, 'lastId' => $result->lastId);
    
            header('Content-type: text/json');
            header('Content-type: application/json');
    
    
          }else{
        $arr = array('Your post has some problems..not posting some of the values');
        }
          echo json_encode($arr);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to post some very simple data to a php file using jquery
I was trying to delete a data from database using jquery and the following
I am trying to get some form data from POST method. Here's the code
I am trying to rewrite some server php code which logs into a website,
i am trying to upload a image to server from iPhone application PHP code
I'm fetching tabular data from the server using jquery's ajax function. And I'm using
I'm trying to POST data from an iOS app to Node.js/Express. I cannot get
If my POST data from a form submission = John Doe, and I'm trying
I'm trying to read the POST data from a request with Transfer-Encoding: chunked while
I'm trying to read POST data in a PHP script. My first instincts led

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.