Home › Forums › JavaScript › refer PHP variable to JS
- This topic is empty.
-
AuthorPosts
-
July 29, 2014 at 2:58 am #176741
mgk89
Participanthello,
I have a dynamic reload script for postings and I would like to know, how I could refer a $_GET Variable to the reload script… the structure is:
index.php
–> here is a certain div, where the content is loaded to via
`
$(document).ready(function(){// Innerhalb der Liste href auslesen und durch # ersetzen, title-Attribut mit dem Wert des href schreiben $("div.list-wrap a").each(function(){ var url = $(this).attr("href"); $(this).attr("title",url).attr("href","#"); }); // per Click entsprechende URL in das DIV laden, aber nur das DIV #seiteninhalt $("div.list-wrap a").click(function(){ var quelle = $(this).attr("title"); $("#content_small").load(quelle); $("#content_small").fadeIn(500); });
});
`
so far this is not problem and works fine.
the file that has been loaded to the div is:
`
<link rel=”stylesheet” type=”text/css” href=”style/dynrel.css”>
<script src=”javascript/dynrel.js” type=”text/javascript”></script><div class=”loader”></div>
<div class=”container”></div>
<div name=”loadlink” class=”loadlink imground” onclick=”loadcontent();”>
<a href=”javascript:void(0);” onclick=”loadcontent();” class=”loadlinklink”>Beiträge laden</a>
</div>
<div class=”end”></div><a name="load"></a>
`
where the postings should be loaded, depending on the category which is defined as ?category=whatever.so far the ?category – variable is accessible , but now when the javascript to reload the posts starts, it seems that this variable is not referred.
the javscript:
`
$(document).ready(function() {
start = 0;
count = 2;
for (var i = 0; i < 1; i++){
loadcontent();
}
});function loadcontent() {
$(“div.loader”).show();$.ajax({ type: 'get', url: 'getarticle.php', async: false, data: { start : start, count : count}, success: function (html){ if(html){ $('.container').append(html); start = start + 2; }else{ $('.end').html('<p>Keine weiteren Posts</p>'); $("div.loadlink").fadeOut('normal'); } } }) $("div.loader").fadeOut('normal');
}
;
`
the problem seems to be that the final php – Page (getarticle.php) does not get the variable $_GET[‘category’].
I’m sorry I know this question seems a little bit roundabout but I hope that the bottom line is kind of clear:
How can I refer a $_GET variable from a php script to another php script that is dynamically loaded via js? I think thats the core question.
Thank you very much for your time and help,
mgk
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.