can't make window.location.reload() inside the ajax call - javascript

Problem
I am not able to refresh the page with window.location.reload() which is used inside the success call made to yahoo.
Any hints how it can be fixed.
The whole of the code is working fine it is making call to cse server getting contents from there saving on yahoo. but i have to manually refresh the page to bring the contents. I want it to be automatic so I used window.location.reload() but thats not working. Any suggestions how it can be done. The function below is actually a function for a button.

That's the problem, right there.
If your script is running from the CSE server's domain, you cannot send data to the yahoo server. This is javascript's main limitations. Likewise, if running off of the yahoo domain, you can send data to it, but cannot send data to the CSE server, unless it is part of the yahoo domain.
Would work:
Get data from blahblahblah.yahoo.com, then send data to somedomain.yahoo.com
Would not work:
Get data from blahblahblah.somesite.com and send data to somedomain.yahoo.com
Main point, if you're getting data from "csce.unl.edu" and running off of that domain (aka running your script in a browser window from that domain), you can only send data to a site that ends with ".unl.edu". So you can send or receive from "test.unl.edu", but not some yahoo site.
A solution:
Host a proxy script on some webserver, or write all of your code in PHP. Here is two great references on what a proxy script is, and the second link actually provides one for you:
Link 1
Link 2
Any more help needed, you can let me know, I had to set one up myself, on my server, and I can help you out if you run into problems.

did you tried:
window.location = window.location;

Related

dynamically generate content for a page when clicking on product

everyone. I am making a website with t-shirts. I dynamically generate preview cards for products using a JSON file but I also need to generate content for an HTML file when clicking on the card. So, when I click on it, a new HTML page opens like product.html?product_id=id. I do not understand how to check for id or this part ?prodcut_id=id, and based on id it generates content for the page. Can anyone please link some guides or good solutions, I don't understand anything :(.
It sounds like you want the user's browser to ask the server to load a particular page based on the value of a variable called product_id.
The way a browser talks to a server is an HTTP Request, about which you can learn all the basics on javascipt.info and/or MDN.
The ?product_id=id is called the 'query' part of the URL, about which you can learn more on MDN and Wikipedia.
A request that gets a page with this kind of URL from the server is usually a GET request, which is simpler and requires less security than the more common and versatile POST request type.
You may notice some of the resources talking about AJAX requests (which are used to update part of the current page without reloading the whole thing), but you won't need to worry about this since you're just trying to have the browser navigate to a new page.
Your server needs to have some code to handle any such requests, basically saying:
"If anybody sends an HTTP GET request here, look at the value of the product_id variable and compare it to my available HTML files. If there's a match, send a response with the matching file, and if there's no match, send a page that says 'Error 404'."
That's the quick overview anyway. The resources will tell you much more about the details.
There are some solutions, how you can get the parameters from the url:
Get ID from URL with jQuery
It would also makes sense to understand what is a REST Api and how to build a own one, because i think you dont have a backend at the moment.
Here some refs:
https://www.conceptatech.com/blog/difference-front-end-back-end-development
https://www.tutorialspoint.com/nodejs/nodejs_restful_api.htm

How to wait for an HTML page and get result when page complitely created?

I have a page (page1.html) and I want to send an ajax to page2.html (http://m-kermani.github.io/getapp.html) and page2.html has an iframe that made by javascript
I made it by javaScript because I need to send a parameter to the page3
In page1.html I have:
$.get('https://m-kermani.github.io/getapp.html', function (data) {
alert(data);
});
and I just need the iframe content but beacuse it made by JavaScript I can't get it and that did not created! (This is the way JavaScirpt is)
I need to send ajax request and get the iframe content because I need an https domain for some reasons that GitHub.io is!
No I need to know is there anyway I can get the content of the iframe from GitHub page?
Is there any other way I can direly just have GitHub page and give the parameter to it and can get the content of the page3 (not using server side language)?
And suggestion about what can I do?
Sounds like you're trying to circumcent the same-origin policy. Unless the API you're trying to access specifically supports a way to do it (CORS, JSONP, etc), you can't do it. You should read the documentation of the API you're trying to access to see if they support accessing it from the client side.
An Ajax request is just a request for a resource. It just gets whatever the server is going to send. It doesn't automatically render the HTML and fetch dependant resources.
If you want the content of a frame, then you have to request the URL for the frame instead of the URL for the page with the <iframe> tag in it.
(The Same Origin Policy will still apply).

ASP.NET call a Javascript function

I'm working on a project that uses IP Payments to process transactions. The project involves a web form written in ASP with Code-Behind written in C#.
IPP offers an iFrame implementation, where you can put an iFrame in your page and display a small IPP page with fields for entering credit card information. The idea behind this is that the credit card info will only be handled by IPP and never by the server running the page, thus there is no requirement to ensure that card data is kept secure.
In order to display the IPP page in the iFrame though, a session needs to be initiated with IPP. The server initiates the session, and passes in a SessionID variable. Upon a successful session initiation, a Secure Session Token is returned to the server. The server then needs to "force" the client's browser to GET or POST the SessionID and the SST (Secure Session Token) to the IPP website. This is where my problem is.
I wrote a Javascript function in the ASPX page that would accept two parameters - the SessionID and SST - and send them to the IPP website. I'm now trying to call this Javascript function from my C# code upon successful initiation of the IPP session. However, I have been completely unable to do so.
I've done a lot of searching, and the one answer I keep coming across is to use either RegisterStartupScript or RegisterClientScriptBlock. The problem is, these seem to insert text directly into the page, rather than calling an existing function. Assuming I inserted my function into the page via one of those functions rather than writing it into the page myself, it still doesn't solve my problem of how to call said function.
Now it is possible that I'm going about this the wrong way, and there's a much better way to get the client's browser to GET/POST the SessionID and SST; if so, please tell me. I'm inexperienced with web programming and am thus learning as I go and making up solutions along the way that are quite likely not ideal.
Thanks in advance.
I think this should work:
Lets say you have something like this in your HTML:
<html>
<head>
<script>
function sendValuesToIPP(sessionId, sst){
//do stuff
}
</script>
</head>
</html>
If you do this in your C# code it should work
ClientScriptManager.RegisterStartupScript(
this.Type,
"some_key_you_want_to_identify_it",
string.Format("sendValuesToIPP('{0}','{1}')", SessionID, SST),
true);
Keep in mind that I'm assuming you have SessionID and SST properties server side, you can get them from wherever you want and just add them to the string that will actually call the function when registered in your ASPX.

Refresh the browser cache for same call to an event updated file

Here is my scenario
Asp. net website
Angular app embedded via IFrame
First user clicks on the .net button that saves a response in a .csv file on the server. On every click different data is updated on the file
Then user clicks on the angular page, which gets the data from that file using a link.
Now the issue is with the caching. Because every time the same link is referred thus, browser shows the data from the previous request and don't actually read the updated file.
The reason I know it is caching issue is because, when I open it on fresh browser I see the updated content. After I run it second time with different request, again it shows me the same data
I have already tried
$http.get(url, {cache: false}
Response.Cache.SetCacheability(HttpCacheability.NoCache);
on my aspx page_load function.
How can I make it to read the updated file? Any help will be appreciated
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Put this code in page load. Now there will be no data in cache browser will try to get the page from the server
Unfortunately I could not found any solution to my problem thus I have changed the logic.
Following is what I am doing now which is perfectly working:
1 Asp. net website
2 Angular app embedded via IFrame
3 First user clicks on the .net button that saves a response in a .csv file on the server. On every click different data is updated on the file. So, I am adding a function that adds the time stamp to name of file on each click
4 Sending the file to the client script via query string hash value . Adding the name of the file as hash value
5 At client side using $scope.$watch, watching the url and on each url change, gets the file name and loads the data from the location.
Now I am facing one more problem which is over here:
Add hash to the current url without reload in c#
If, anyone can help me with that?
Thanks

Cross Domain AJAX query

With the help of Stack overflow I currently have this JSFiddle: http://jsfiddle.net/WskJT/
I have an aspx file on another server (cannot access this, so amendments to that server are not an option) and offline (php include not an option) I would have a page that pulls this data & removes columns as per the above fiddle.
Is there any workaround to be able to get this data from the aspx file & display (something similar to) the output the the above fiddle?
I'm an enthusiastic novice so I apologise if I haven't worded this correctly etc.
Thanks in advance!
Despite the server being on your intranet as you have indicated in your comments you will face security issues as pointed out. What you could do is create a 'proxy' web service in the same domain as your main page.
Start by creating a 'service.php' file on your own server. From there, make the necessary curl calls to the ASPX page on the other server. Any time service.php (or call it proxy.php if you like) is called, it in turn calls the ASPX page, with any parameters as required. Have it read the output text and return the text to the caller itself.
Point your AJAX code to the 'service.php' file.
Now your javascript calls are in the same domain and you shouldn't have the permission problems you were facing with the JavaScript.

Categories