i have two pages, lets say:
webpage1.com, and
webpage2.com
webpage1 contains
page.html - contains reference variables in accessing the proper data stored in webpage2.com. one reference variable may be stored in localStorage
webpage2 contains
page.html - contains the layout of the whole webpage
page.php - contains the information being worked at behind the scenes, also this guy should fetch the data i send from webpage1.
i know you guys may say something like ajax is the way to go. but webpage2 is already using an AJAX function on its plugin (yes webpage2 has a plugin that i need), so ajax is already not an option as for me. i also tried passing a string parameter on the url but webpage2's page.php just won't respond on $_GET when i try to fetch it.
i'm thinking of something like a variable that is capable of being shared cross domain. like for example cross-domain localStorage, or cookies, or $_SESSION.
lastly, webpage1 and webpage2 has a different server.
i hope you guys understood. thanks
Related
I would like to extract specific data from a webpage then open a specific webpage based on what that data is. In the form of an if statement.
Say for example I google the olympics (https://www.google.com/#safe=off&hl=en&q=olympics&btnK=Google+Search)
It says it is in "Rio" right now. Say based on "Rio" I have a link that directs to Wikipedia and if it said something other than "Rio" it directs to www.google.com. I need to find a way to be able to pinpoint the data I need from another webpage then make a decision based off of that. The hard part being assigning that data to a variable.
I would like to do this in jQuery if at all possible. If not what language what I need to do this? Is there a specific name for this type of thing (pulling data off of webpages) and are there any resources so I can learn more about it?
Thank you
I think its what you are looking for. Correct me if i'm wrong
You can use the PHP method on a file called go.php
<?echo get_file_contents($_GET['a']); ?>
and call it from AJAX using:
$.get("go.php?a=https://google.com", function(data){
//Your code....
});
IMPORTANT: DON'T FORGET THE HTTP OR HTTPS, if you forget it, go.php will try to find google.com in your server.
This method doesn't load the images because it tries to load them from your server
I am setting cookie using JS script on my page, but I need to use this value while generating HTML on server side PHP.
Let me expalain.
User requests page - > Of course PHP starts generating HTML -> User get response from server -> JS sets cookie.
Am I correct ? I understand this in this way.
But I need to use cookie set by JS while PHP generating response.
Of course it will work if reload the page,because new request is sent with cookies. But I need to use this cookies at a time I set it in JS.
Of course I can set in JS to reload page, but I don't think that is good solution.
What are possible solutions. I don't need to adhere to cookies. Maybe there are other possible ways to get data from JS to PHP.
If I understand your question right, there are at least 2 different ways:
load an initial page which purpose is to redirect (via JavaScript or Refresh header) to the main page;
load the entire main page in the first request, containing a placeholder block. Then set the cookie. Then fill the placeholder using AJAX technique (send another request using JS and replace HTML content of placeholer with a newly generated one).
For the 2nd approach you don't even need cookie, as JS can pass the value with a query string (GET request parameter).
I want to pass javascript object/ variable from page to another. so that i can use data for some fields, i want this values to be hidden and not visible while i my passing value from one page to another
I have already seen many examples of pass via http parameters, i dont want that and also session variables manage on server side, cause nothing has to be manage on sever side for that page.
i want to pass value as a hidden field or value to next page. how to pass it to new page when i open new page via
window.location="website/nextpage.jsp";
Also a note, i am beginner, so please sorry if the question seems to vague.
You can:
Use hashes in the url by reading the window.location.hash. Similar to GET requests, but does not need the server for passing. However, the parameters are visible in the url.
Using cookies. Have JS "plant" the cookies on the previous page and read them on the receiving page.
You could use DOM storage as well. Similar routine as cookies, plant and read.
Assuming you do not want to use session variables, cookies or local storage:
You can not "hide" a parameter so that your website user will not be able to see it.
If you submit data via a POST request - you can use hidden form elements.
<form method="post">
<input type="hidden" name="state" value="{YOUR PARAMETER}" />
If you use window.location - you will have to do it with a GET request
window.location="website/nextpage.jsp/param/{YOUR PARAMETER}";
I don't know about JSP specifically, but using a form with POST method hides data from (standard) users.
why dont you use html5's localStorage and sessionStorage for the purpose. for more help visit here
Is it possible to retrieve a div ID from another file via a javascript from one file.
Example:
Lets say you are editing index.html and want to retrieve an ID, using getElemntById from page2.html.
I understand that you can use document.getelementbyid; if you want to get the id from the same document, but is there anything you can use to get it from another document?
Thanks in advance
You will have to make an AJAX call to page2 first.
Paste the response of XMLHTTPObject in some invisible div.
Then get the required div that you want to retrieve.
Personally, I would create an include file with the content you require on both pages, and include it on both pages. Then it would just be a matter of showing/hiding the div.
You can do this fairly easily with AJAX - you have to make an asynchronous call to page2, and then process the response to get the element you're looking for. Look up jQuery's get() method for an easy AJAX implementation - it handles the details of the XMLHTTPRequest for you.
It's also worth noting that if page2 is a page served by your server, an even easier solution is just to copy whatever information you need from page2 to page1 on the server side. Alternatively, if you do need to do an AJAX call because it isn't feasible to put all the information you might need onto page1 from the beginning, you can have your server (using php, Rails, Django, etc.) return different information for an AJAX call. So you can have it return only the info you need, rather than returning the entirety of page2.
How should I proceed in achieving the following:
I need to get the data from another server which is a jsp page it has the data related to the information i want to show in tooltip. The code for this is working and I can make ajax call to get the response.
The concern is that I want the contents of qtip library to fit in the page since the page doesn't allow cross domain contents. If I will try to just reference the contents of qtip saved on my website(the domain is different from the page which I am using) it wont allow to do this. so is it fine embedding the contents in the main form or there is some other optimal way?
Similar question was asked:
How to display information returned by ajax call in a tooltip
If you can't reach cross domain via AJAX you can always uses an intermediary script (in your case Java) to output a buffer containing the information you want in the qTip.
Script calls digest.jsp?params=someparameters
digest.jsp fetchs the information from any domain it needs.
outputs the information in a buffer in XML o JSON
with javascript you parse the information an put it in the option attribute.
If it doesn't work for you nor you want to do it you can always relay in putting the information in each title="" attribute in each option.