user1326293
user1326293

Reputation: 933

passing data between different pages on document

I have a page which loads via .load() another page's div, for example:

$(".page_div").load("otherpage.aspx .wrapper");

I want otherpage.aspx to inform about an event that happened to the parent page, how do I do that?

Upvotes: 1

Views: 149

Answers (3)

Jason Sperske
Jason Sperske

Reputation: 30446

When you load a page via jQuery.load() it can contain a script element. Any JavaScript inside that script element will execute after the page is loaded and because it is inside the parent document it has full access to the parent JavaScript. This means it can call JavaScript methods created by the parent document. I would create a method like loadCallback() in the parent document and then add a script element with the JavaScript loadCallback({some: data}) this will pass data from the loaded page out to the parent page. This is vanilla JavaScript so you can pass data, functions, anything.

Upvotes: 0

ShaggyInjun
ShaggyInjun

Reputation: 2973

I think there is a mixup here. Can't say whether you are making an ajax call or doing a page trasition.

  • Use query strings for page transition.
  • If you are making an ajax call that information is already available, use it inside the callback function that will be called once the server call returns.

Based on what I read on the api page, jQuery.load can be used to make an ajax call.

http://api.jquery.com/load/

Edit:

I am not familiar with web sockets, but something like that can be achieved like this.

From page 2 you update a database entry when the event occurs

from page one you poll for changes in the database via ajax.

You notice a similar behavior in Gmail when user sends a new email from a different tab and your email sent list gets updated automatically.

Upvotes: 0

cereallarceny
cereallarceny

Reputation: 4983

Look into query strings! If you want to pass information from one page to the next, generally the best way to do so is by appending the information into the URL you pass.

Technically you could also use cookies or sessions, but those involve the creation of information rather than the "speaking" of information.

Upvotes: 1

Related Questions