var http_request = false;
function makePOSTRequest(url) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,…
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
// set type accordingly to anticipated content type
//http_request.overrideMimeType(‘text/xml’);
http_request.overrideMimeType(‘text/html’);
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject(“Msxml2.XMLHTTP”);
} catch (e) {
try {
http_request = new ActiveXObject(“Microsoft.XMLHTTP”);
} catch (e) {}
}
}
if (!http_request) {
alert(‘Cannot create XMLHTTP instance’);
return false;
}
http_request.onreadystatechange = alertContents;
http_request.open(‘GET’, url, true);
http_request.send(null);
}
function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
//alert(http_request.responseText);
result = http_request.responseText;
document.getElementById(‘img_spin’).style.display=’none’;
alert(result);
if(result==’1′) {
document.getElementById(‘txtuser’).disabled=true
document.getElementById(‘txtpass’).disabled=true
document.getElementById(‘div_err’).style.display=’none’;
}
else if(result==’0′){
document.getElementById(‘txtuser’).disabled=true
document.getElementById(‘txtpass’).disabled=true
document.getElementById(‘div_err’).style.display=’block’;
}
} else {
alert(‘There was a problem with the request.’);
}
}
}
function get() {
document.getElementById(‘img_spin’).style.display=’block’;
var poststr = “user=” + encodeURI( document.getElementById(“txtuser”).value ) +
“&pass=” + encodeURI( document.getElementById(“txtpass”).value );
//alert(poststr);
makePOSTRequest(‘__pro/pro-post.php?’ + poststr);
}
June 19th, 2008 | Posted in Scripts | No Comments
var http_request = false;
function makePOSTRequest(url, parameters) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,…
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
// set type accordingly to anticipated content type
//http_request.overrideMimeType(‘text/xml’);
http_request.overrideMimeType(‘text/html’);
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject(“Msxml2.XMLHTTP”);
} catch (e) {
try {
http_request = new ActiveXObject(“Microsoft.XMLHTTP”);
} catch (e) {}
}
}
if (!http_request) {
alert(‘Cannot create XMLHTTP instance’);
return false;
}
http_request.onreadystatechange = alertContents;
http_request.open(‘POST’, url, true);
http_request.setRequestHeader(“Content-type”, “application/x-www-form-urlencoded”);
http_request.setRequestHeader(“Content-length”, parameters.length);
http_request.setRequestHeader(“Connection”, “close”);
http_request.send(parameters);
}
function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
//alert(http_request.responseText);
result = http_request.responseText;
document.getElementById(‘img_spin’).style.display=’none’;
//alert(result);
if(result==1) {
document.getElementById(‘txtuser’).disabled=true;
document.getElementById(‘txtpass’).disabled=true;
//alert(result);
document.getElementById(‘div_go’).style.display=’none’;
document.getElementById(‘div_err’).style.display=’none’;
}
else if(result==0){
document.getElementById(‘div_err’).style.display=’block’;
}
} else {
alert(‘There was a problem with the request.’);
}
}
}
Call this function in OnClick Event Of Image/Button To get the effect.
function get(obj) {
document.getElementById(‘img_spin’).style.display=’block’;
var poststr = “txtuser=” + encodeURI( document.getElementById(“txtuser”).value ) +
“&txtpass=” + encodeURI( document.getElementById(“txtpass”).value );
//alert(poststr);
makePOSTRequest(‘__pro/pro-post.php’, poststr);
}
June 19th, 2008 | Posted in Scripts | No Comments
// FUNCTION Starts ….
function getPageURL()
{
$pageURL = ‘http’;
if ($_SERVER["HTTPS"] == “on”) {$pageURL .= “s”;}
$pageURL .= “://”;
if ($_SERVER["SERVER_PORT"] != “80″) {
$pageURL .= $_SERVER["SERVER_NAME"].”:”.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
}
Note : Use This Funtion To Get The Dynamic Page URL.
April 13th, 2008 | Posted in Scripts | No Comments
When we REFRESS web page containing IFRAME, the page reloades with the starting page. Here is the solution being in the existing page after refress. (PHP Script)
Generally what happens, when we refress a web page containing IFRAME ? The page reloades with the starting page. Information provided in the existing page are lost. this is a big problem with Iframe. Here is a way to solve this problem in php script, the can be solved in any scripting languages. See it and try ….
STEP 1: First declare a iframe in aweb page. Let the name of the web page be index.php
<iframe src=”<?php echo $_COOKIE['pagename']; ?>” width=”738″ height=”500″ frameborder=”0″ name=”second” scrolling=”Yes”></iframe>
STEP 2: Now I want to load process.php page in that iFrame when I click on the submit button in index.php page.
<?php
header(‘Location: process.php’);
?>
STEP 3: Now insert the following code in the process.php page.
<?php
ob_start();
setcookie(‘pagename’, ‘process.php’);
// Please never forget to recover the values using $_GET['']
?>
Now See the magic. Now press F5 To refress the page. You will see that the the Iframe will reload with the existing page.
Note : If you have got any problem with web programming then sent your message as comment with your email. Coder Circle is ready for you…
January 26th, 2008 | Posted in Scripts | No Comments
Generally, when we access javascript, wild card charecters are replaced by some special symbols (like +,% etc). This code is for accessing cookie value withour any special chacters. Try It.
//Reading Cookie
function ReadCookie(n) {
var cookiecontent = new String();
if(document.cookie.length > 0) {
var cookiename = n+ ‘=’;
var cookiebegin = document.cookie.indexOf(cookiename);
var cookieend = 0;
if(cookiebegin > -1) {
cookiebegin += cookiename.length;
cookieend = document.cookie.indexOf(“;”,cookiebegin);
if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
cookiecontent = document.cookie.substring(cookiebegin,cookieend);
}
}
return unescape(cookiecontent);
} // This Code is for reading cookie value. But the output will consist of ‘+’ sign in the place wild card charecters. To remove this ‘+’
//use the following function.
function get_body()
{
var ind = document.form2.lstmessage.selectedIndex;
var string=ReadCookie(ind);
var strReplaceAll = string;
var intIndexOfMatch = strReplaceAll.indexOf( “+” );
// Loop over the string value replacing out each matching
// substring.
while (intIndexOfMatch != -1){
// Relace out the current instance.
strReplaceAll = strReplaceAll.replace( “+”, ” ” );
// Get the index of any next matching substring.
intIndexOfMatch = strReplaceAll.indexOf( “+” );
}
//alert( strReplaceAll );
document.form2.txtbody.value = strReplaceAll;
}
Cookies in Javascript
/ _________________Function To Create Cookie In Javascript____________________ //
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000))
var expires = “; expires=”+date.toGMTString()
}
else var expires = “”
document.cookie = name+”=”+value+expires+”; path=/”;
}
// _________________Function To Read Cookie In Javascript____________________ //
function ReadCookie(n) {
var cookiecontent = new String();
if(document.cookie.length > 0) {
var cookiename = n+ ‘=’;
var cookiebegin = document.cookie.indexOf(cookiename);
var cookieend = 0;
if(cookiebegin > -1) {
cookiebegin += cookiename.length;
cookieend = document.cookie.indexOf(“;”,cookiebegin);
if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
cookiecontent = document.cookie.substring(cookiebegin,cookieend);
}
}
return unescape(cookiecontent);
} // function ReadCookie()
Note : If The cookie contents consist of some ‘+’ symbol then use the following code to filter the cookie contect. The
Following function is to remove the + symbols from the cookie content. It can be used for removing other special charecters from the cookie content. To use the following code to remove other special charecters, simple replace the ‘+’ symbol by the special symbol in star(//***********************//) marked line..
var string=ReadCookie(ind);
var strReplaceAll = string;
var intIndexOfMatch = strReplaceAll.indexOf( “+” ); //***********************//
// Loop over the string value replacing out each matching
// substring.
while (intIndexOfMatch != -1){
// Relace out the current instance.
strReplaceAll = strReplaceAll.replace( “+”, ” ” );
// Get the index of any next matching substring.
intIndexOfMatch = strReplaceAll.indexOf( “+” );
}
Author – Dhiraj Das
From – Skillhut
January 26th, 2008 | Posted in Scripts | 1 Comment