开发者

Accessing the data used in .load()

开发者 https://www.devze.com 2023-02-15 06:10 出处:网络
When using the .load() method to load some external php/HTML, how do you access the data in the external file?

When using the .load() method to load some external php/HTML, how do you access the data in the external file?

Say the first file is 'index.php' and it contains something like;

$('#contentContainer').load('productContent.php',{param1:'data.xml'});

inside 'productContent.php' I want to be able to parse di开发者_Go百科fferent XML files by passing the XML filename as shown. However, I don't know how to get access to 'param1' from within 'productContent.php'


It will be there under

$_REQUEST['param1'];

Edit: On the server you need a file called productContent.php like this:

<?php
    echo $_REQUEST['param1'];
?>

Edit2: If you are writing JavaScript in your PHP file (which I think is a bad idea, JavaScript files should generally be kept away from the generated HTML) then you'd do something like this:

$(this).ready(function () {
  var d = <?php echo $_REQUEST['param1']; ?>;
});

But this is pretty messy.

0

精彩评论

暂无评论...
验证码 换一张
取 消