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.
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);
}
);
In the loaded page you need to do:
var arr = window.location.match(/[^?]+\?azione=(.+)/);
var azione = arr[1];
alert(azione);
Demo
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.
I am not sure if this helps:
If you load the div, add a callback to load. When the HTML was loaded, set the value of a hidden field (div or input or whatever) and use this in JS.
Example:
$('#mydiv').load(someurlwithparams, functions() {
$('#myhiddenfield').val(someurlwithparams);
executeSomethingThatUsesTheParams();
});
And HTML:
<input type="hidden" id="myhiddenfield">
<p>Rest of loaded HTML</p>
AND JS:
function executeSomethingThatUsesTheParams() {
var queryString = $('#myhiddenfield').val();
alert('Query for loaded div: ' + queryString);
}
You could also pass the query string to executeSomethingThatUsesTheParams directly. Not sure if useful, just a thought...
精彩评论