0

i have a php array:

$Array= array ($eventRow['title'], $eventRow['start_date'], $eventRow['start_time'], $eventRow['end_date'], $eventRow['end_time'], $eventRow['description'], $eventRow['address']);

i am exeucing an ajax script with a html button, and i would like to get these variable's values as the following:

(document).ready(function() {

    //##### send add record Ajax request to outlookimport.php #########
    $(".exportOutlook").click(function() {

        /*var myData = {
            title:
            startDate:
            startTime:
            endDate:
            endTime:
            description:
            address:
            username:

        };*/
...

any idea how to get the values in the JS file when processing the ajax query? after this, a php file as called by the ajax, when i would like to get the variable as the following:

$title = $_POST['title'];
$startDate = $_POST['startDate'];
...
...

any idea would be appreciated

2 Answers 2

1

In jQuery, it's:

$.post('outlookimport.php', myData, function (returnedData) {
    //Do something
});

By including myData as the second parameter, its values will be posted to the PHP script.

0

Use json_encode($Array) and read the JSON response in your ajax request on success.

$.ajax({
    type: 'POST',
    url: 'outlookimport.php',
    data: myData,    
    success: function(response){
        console.log(response);
    }
});
2
  • you mean here? : jQuery.ajax({ type: "POST", // HTTP method POST or GET url: "outlookimport.php", //Where to make Ajax calls dataType:"json", // Data type, HTML, json etc. data:myData, //Form variables success:function(response){ }, error:function (xhr, ajaxOptions, thrownError){ } Commented Sep 17, 2014 at 0:15
  • @user3576148 are you echoing the array as json format in your php ? see my answer Commented Sep 17, 2014 at 0:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.