0

I am working on javascript and jquery. In page1 there is an edit symbol (which have "news" and "image" as attributes like, news="news1" image="image1.jpg").

When click on that symbol it takes us to the other page (in href i mentioned the page url).Now in this page2 i want to get those attributes. I tried as follows but doesn't work

How can i get those values..? I put that code in onload and document.ready

NDM
  • 6,731
  • 3
  • 39
  • 52
Divya
  • 31
  • 1
  • 9

2 Answers2

1

Consider sending values "news1" and "image1.jpg" to page2 as URL arguments:

<page2 URL>?news=news1&image=image2

Edited:

Can you place your data into hidden inputs inside a form, and use your link to submit it (onclick="form.submit();")?
This way you'll make a POST request instead of GET.

Kniganapolke
  • 5,073
  • 5
  • 22
  • 19
  • Yeah i can do like that but the news attribute includes multiple lines of text..I also searched for maxlength of url in all the browsers..app. 2083 in IE 65536 & 100000(after 65536 we are unable to see the url content) in Firefox but better to have min lenght as 100 oherwise "413 entity too large" error will occur.Just now i got to know about load() in jquery which works as :http://api.jquery.com/load/ But it doesn't work on dynamically added data.It's working fine for static data..Already I tested id.I put this in window.onload=function(){}Thanks in advance.. – Divya Aug 02 '13 at 09:13
1

I think you can put the two attributes as parameters in the 'href' of the 'a' in page1; like:

href="xxx.com/xxx/?news=new1&image=image1";

and in page2 you can get the two parameters in the URL and then use it;

zqillyc
  • 21
  • 3
  • Yeah i can do like that but the news attribute includes multiple lines of text..I also searched for maxlength of url in all the browsers..app. 2083 in IE 65536 & 100000(after 65536 we are unable to see the url content) in Firefox but better to have min lenght as 100 oherwise "413 entity too large" error will occur.once refer this..It doesn't work for dynamically added data..Thanks in advance.. – Divya Aug 02 '13 at 09:11
  • then i think you can use LocalStorage or SessionStorage(if supported); or use cookie. – zqillyc Aug 02 '13 at 09:18
  • http://api.jquery.com/load/ once refer this please..tell me how to use this on dynamic data.. – Divya Aug 02 '13 at 09:22
  • i am confused, is there anything related to jquery or load(); you said 'I tried as follows', i can't see the 'follows'. – zqillyc Aug 02 '13 at 09:31
  • yeah..link was missed there..sorry..api.jquery.com/load window.onload=function(){ $('#divya').load('extraInfo.html #testing'); } In extrainfo.html an element with id "testing" was there..Its content is placed in my page2 properly..but i want to access the element from page1 which is dynamically loaded data – Divya Aug 02 '13 at 09:37
  • i think you'd better use SessionStorage to get the two attributes;load() can get datas that are static on server, i don't think it can get dynamic datas; – zqillyc Aug 02 '13 at 09:50
  • ok..but i dont know how touse sessionstorage can you please help me..?Iam pretty new to this field.. – Divya Aug 02 '13 at 09:55
  • in page1 you can use `var pagedata = {news : new1,image : image1}, sessionStorage.setItem('pagedata',JSON.stringify(pagedata));` and in page2 you can use `var data = JSON.parse(sessionStorage.getItem('pagedata')); var image = data.image1;var news = data.news; ` – zqillyc Aug 02 '13 at 09:58
  • and i think the best way for this question is in page2 you let the server gives you the two data. – zqillyc Aug 02 '13 at 10:09
  • ok..then i will follow the second one..Actually what the problem is,now i changed the structure.I thought with trivial changes i can get the output as earlier..It seems difficult to get..edit(have attributes of news and image)-->click-->$(this).attr("news")-->like wise i structured but now edit-->separate page-->here unable to get those values; but in url i have the data by which the output met my requirement..Thank you so much.. – Divya Aug 02 '13 at 10:37
  • once refer this please : http://stackoverflow.com/questions/18052358/parameters-in-the-page-url-are-lost-when-clicking-on-any-button – Divya Aug 05 '13 at 07:33