Dave
Dave

Reputation: 37

load php variable with jquery and work with javascript

I want to load a php variable and want to use it for javascript

$(document).ready(function() {
    $('#reload').load('http://www.domain.de/content/entwicklung/reload.php?uid=' + uid_clear + '');
});

From this code I get a var but I can only load this into a div

if (uid_clear == ..) {
    // want to replace the dots with the data from .load
    document.write(' Allgemeine Reloadsperre für das Mitglied von 30 Minuten');
}

How can I load the data into a div and use it as a javascript var ? Is there any way to transfer/change it or is it possible to load the data already as a javascript var ?

kind regards

Upvotes: 0

Views: 90

Answers (2)

Tom Walters
Tom Walters

Reputation: 15616

Use $.get like so:

$.get( 'http://www.domain.de/...', function( data ) {
  if (uid_clear == data) {
    // want to replace the dots with the data from .load
    document.write(' Allgemeine Reloadsperre für das Mitglied von 30 Minuten');
  }
});

Check out the documentation for more info about the get method.

Upvotes: 2

yeyene
yeyene

Reputation: 7380

Make a hidden input, put your PHP variable in this hidden input, instead of into div. Then get this html value in js with js/jquery.

HTML

<input type="hidden" id="my_value_from_php" value="<?php echo $your_PHP_var; ?>"/>

JQUERY

var uid_clear = $('#my_value_from_php').val();
// you can use your js variable now

Upvotes: 0

Related Questions