1

I am using jquery load to load another html page which contains js code and was to know what value has been passed.

var code = 1000
$('#content').load('forward.html?entity=' + code );

so far: I have got a function in forward.html, which is something like:

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/,"\\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

by calling getParameterByName (entity) will not give me the value as expected but nothing as this function is reading the parameter string from the original calling page, (or what-so-ever is inside the URL address box).

Would someone please let me know how to resolve this problem? is there anyway to retrieve the parameter as expected? any JQuery function to do it so?

Joe
  • 15,205
  • 8
  • 49
  • 56
user2625363
  • 845
  • 2
  • 10
  • 15
  • 1
    I am not sure but I think you can just use your `code` variable directly if the two pieces of code are in a same js file. I don't think there is a way to retrive the `querystring` as it is a server call. But Hey Its just me and I had thought a lot of things were impossible in the past which were decently easy to acheive – user1 Sep 26 '13 at 14:29
  • try `getParameterByName("entity")` (note: the quotes) – Populus Sep 26 '13 at 14:50
  • Also please try to credit the code's creator: http://stackoverflow.com/a/901144 – Populus Sep 26 '13 at 14:51

1 Answers1

0

If you make forward.html into a php file you could easily add the $_GET params to a element and then retrieve it with javascript. so

forward.php

<?
 echo 'YOUR CONTENT TO BE LOADED
 <div id="passed-data" class="hidden" entity="'.$_GET["entity"].'"></div>';
?>

or forward.jsp

YOUR CONTENT TO BE LOADED
<div id="passed-data" class="hidden entity="<%= request.getParameter("entity") %>"></div>

and on frontpage

$('#content').load('forward.html?entity=' + code, function(){
    // entity now becomes code. so you could just do var entity = code;
    var entity = $("#passed-data").attr("entity");
});

Or just use the value as user1 pointed out. you use it when loading the html as the var code.

Karlton
  • 116
  • 3
  • Well i think you should be able to do the same thing in jsp. but you cant do it in html. not this way atleast – Karlton Sep 26 '13 at 14:36