Phil
Phil

Reputation: 2446

Load a Page with Ajax and sent Data to the Page

I have a page where I generate a javascript Array and I want to send it to the berechnungsauswertung.php page and load that page. And than I want to use the data at this page in php.

$.ajax({
        type : 'post',
        url : 'berechnungsauswertung.php',
        data : {
            marker : JSON.stringify(data),
            homemarker : JSON.stringify(datahome)
        },
        complete : function(data){
            $('body').load( "berechnungsauswertung.php" );               
        }
    });

on the next page I want to get the Variables

$marker = json_decode($_POST['marker']);
$homemarker = json_decode($_POST['homemarker']);

but it does not work. How can I load a Page like this?

Upvotes: 0

Views: 115

Answers (1)

Quentin
Quentin

Reputation: 943220

This is what you are doing:

  1. Make Ajax request with POST data
  2. Ignore the response
  3. Make Ajax request without any data
  4. Include the content in the page

It doesn't work because you don't have the data from 1 when you are loading the new content in 4.

Replace your complete function with a success function. Do something with the data you get (the first argument to the success function) such as passing it to jQuery('something').html(data).

Don't use load at all.

Upvotes: 1

Related Questions