views:

45

answers:

3

hi everybody,

I have a page with a form page loaded in a div. I'd like to send some data to the loaded page by querystring and read the content in it, is it possible and if yes how?

that my example:

$("#scheda_sch").load("./schemi/sch_"+schemi[indice]+".html?azione="+azione); 

I need to read from page sch_...html read the value of querystring azione

thanks in advance ciao h.

+1  A: 

You can't do that. The URL with the query string is sent to the server, and the response is placed in the element. Any code that is loaded will know the URL of the current page, not the URL of the code that was added to it.

What you can do is to use the callback that occurs when the content has loaded. As you declare it in the same scope as the method starting the load, it has access to the variable:

$("#scheda_sch").load(
  "./schemi/sch_"+schemi[indice]+".html?azione="+azione,
  function(){
    alert(azione);
  }
);
Guffa
Thanks for answering Guffa! Now I'm cert of what I supposed :(
haltman
A: 

In the loaded page you need to do:

var arr = window.location.match(/[^?]+\?azione=(.+)/); 
var azione = arr[1];
alert(azione);

Demo

galambalazs
Thanks for answering galambalazs but with window.location i can't get querystring of loaded page in div but querystring of main page.
haltman
right, i misunderstood your question.
galambalazs
A: 

I find a solution that work for me I simply transformed my loaded page from html to php and posted azione in this way:

$("#scheda_sch").load("./schemi/sch_"+schemi[indice]+".php", {azione: azione});

ciao h.

haltman