0

I have the following variable in Javascript. I want to know how to pass this data to a PHP so that I can display the contents of the data once redirected.

    postData = {
        'dates_ranges': datesAndRanges,
        'action':'build',
        'output_type': output_type,
        'form_html': formHtml,
        'width': formBuilder.width(),
        'rules':validationRules,
        'theme': theme,
    };
3
  • Have you done some research before posting your question? Commented May 5, 2012 at 20:17
  • As for me, I don't really understood the question. Commented May 5, 2012 at 20:20
  • The same question: stackoverflow.com/questions/4210025/… Commented May 5, 2012 at 20:21

3 Answers 3

1

Use JQuery post method to pass data to PHP file:

$.post("/path/to/script.php", postData, function(result) {
    // work with result
});

In PHP use $_POST global to get the variables:

print $_POST['dates_ranges'];
print $_POST['action'];
// ...
Sign up to request clarification or add additional context in comments.

Comments

0

using jquery it goes easy & clean like this:

$.post('script.php', postData, function(response){ 
    // process/display the server response 
});

1 Comment

There is no need to serialize postData.
0

you can use:

$.post("YOUR_URL", postData, function(response) {
    // handle with response
});

OR:

$.ajax({
  url: YOUR_URL,
  data: postData,
  type: 'post',
  success: function(response) {
    // handle with response
  }
});

And In your PHP file:

if(isset($_POST) && !empty($_POST)) {
   $d = $_POST;
   echo $d['date_range']; // and so more
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.