This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
How to check if a page is exist or not using javascript
can you provide the code for checking the page exist or not.if not,it will redirect to another page.
The problem is, if the page doesn't exist (the server is given what it considers an invalid url that it cannot satisfy), you will get a 404 error. So no code on any target page is going to run. Instead you have to do this server side, specifying what page to serve instead when a 404 is encountered. It is not done with client-side javascript.
Related
This question already has answers here:
Sending PHP GET data to server using Html links
(2 answers)
Closed 4 years ago.
I know that requests placed by jQuery $.get() can include an optional parameter for additional data. I was wondering if there was any way to pass that information through requests that come about by clicking an link, or relocation the windows location.
Yes, you can use a Query String.
Excerpt:
Typical URL containing a query string is as follows:
http://example.com/over/there?name=ferret
When a server receives a request for such a page, it may run a program, passing the query string, which in this case is, name=ferret unchanged, to the program. The question mark is used as a separator, and is not part of the query string.
So your anchor could be:
My Link
or
My Link
or
My Link
Be aware that you can get caching issues by links/get requests.
The only way to pass data through a link as the page is visited is to use URL Parameters/Query Strings.
This question already has answers here:
Can I perform a DNS lookup (hostname to IP address) using client-side Javascript?
(16 answers)
Closed 4 years ago.
I need to check whether my email address has valid host, exist for example someone#yahoo.com might return valid meanwhile some#yahozzz.com might return invalid (because invalid host)
I stumbled upon a code in git for golang that satisfy my needs for that https://github.com/badoux/checkmail, but currently at the moment i'm looking for the solution in javascipt, any help will be appreciated.
P.S. : I am using this code as a script inside my HTML
Actually to verify that an email exists and is active you have to send a message to the email server and check the response.
That cannot be done entirely in javascript although you can rely on a service instead than on your backend like this
This question already has answers here:
Why PHP script is not workig in a web browser?
(9 answers)
What is the difference between client-side and server-side programming?
(3 answers)
Closed 4 years ago.
Okay, here are something I have now.
I'd like to use $_SESSION['pass'] in my other php files to make it as a condition to check whether an if condition is true. But it seems that the system only shows the alert part and never runs the code in the PHP tag.
Thanks a lot!
document.getElementById('pass').onclick = function(){
<?php $_SESSION['pass']=1; ?>
alert('here!');
}
document.getElementById('fail').onclick = function(){
<?php $_SESSION['pass']=0; ?>
alert('there!');
}
PHP is a server-side scripting language whereas JavaScript is a client-side scripting language. PHP runs in the back end on the server whereas JavaScript runs in the front end on the browser. PHP can be used to generate dynamic content for the browser. In your case, it seems like you want to set value of a session variable based on condition in the JavaScript code. PHP blocks in your code are executing in first place on the server which runs all PHP blocks by first setting $_SESSION['pass'] as 1 and then to 0 in the next PHP block. The resulting HTML is then sent to the browser for display. If you want to change the value of session variable based on the button user clicks, then you will need to do it using AJAX request.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Client-side detection of HTTP request method
I'm working on Javascript that is injected on any page. The script is injected on servers that I'm not controlling. (Injection is done with an add-on or bookmarklet.)
The Javascript needs to know whether the page was loaded as the result of an HTTP GET or POST. The reason for this is that if the page was loaded with a GET, the URL is an identifier for the page that can be bookmarked, shared with others, etc. In case of a POST, I need to handle it differently.
Can this be done? I have found no way of accessing the request from Javascript, but perhaps there is some trick that I don't know of.
I think you can't.
Brendan Eich just confirmed that last night on his twitter, in a conversation with dhh.
Reproducing here:
#dhh: Is there any continued reason why JavaScript can't access HTTP headers in the browser outside of Ajax? And what's the historic reason?
#BrendanEich: #dhh #lostconvos no good reason -- I had no time in the old days (apart from document.cookie and navigator.userAgent), no one followed up.
#dhh: Could we just borrow the API from xhr: getResponseHeader() and getAllResponseHeaders()?
I suggest you follow both in case you are interested on this matter.
In the meantime, I think the best you can do is having two different javascripts - one for POST pages and another one for the rest. You give both to your providers and tell them how to use them. But yes, this involves cooperation from the servers.
It's not possible to directly retrieve the POST data of a webpage; Imagine that it's possible. Then, the sensitive data, submitted through a POST request can also be read, which is obviously not desired.
If you're writing an extension/userscript which has control over the generated HTML, you can append a query string to each form element with method=post. This method is only reliable if the POST requests are not scripted (AJAX), but initiated through a form.
Example code:
javascript:(function(){
var form = document.forms, i=form.length-1;
for(; i>=0; i--) {
if(/post/i.test(form[i].method)) form[i].action += "#method-post";
}
//check whether the hash contains `#method-post`
var is_post = location.hash.indexOf("#method-post") != -1;
//Optionally, remove the hash to not interfere with the scripts at the page:
//location.hash = location.hash.replace('#method-post', '');
})();
Location hashes are not submitted to the server, but passed by the browser. This solution works perfectly for extensions, but possibly inaccurate for bookmarklets, since the user should always activate it.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Making a hack proof game in Javascript
I'm building a very simple web game
In this game when player clearing all missions the total score should be posted to server .
question is : ajax params could be modified easily .
How to check if datas modified ?
There are several diferent solutions.
You can check you server script that processing your AJAX data, and then logged them.
Another way is to use your browser console. The most of the new Web Browsers are having console, that allowing you to check all the data of your web page, even the data you send or receive from the server with AJAX Calls.