Page 1 of 1
During production the AJAX result from xmlHttp.responseText
Posted: Mon Aug 27, 2007 9:38 pm
by rozvinbm_jp
During development (debugging) the site works well but when I release from the debugging and test into production.. All the AJAX was not performed.. the result from xmlHttp.responseText was not displayed.
I added an alert in order to check if the script was called. The alert was displayed.
Posted: Mon Aug 27, 2007 9:45 pm
by feyd
Is your post in reference to another of your threads, a new problem, or is it merely a random statement?
Posted: Mon Aug 27, 2007 11:22 pm
by rozvinbm_jp
feyd wrote:Is your post in reference to another of your threads, a new problem, or is it merely a random statement?
What do you really mean Sir? Sorry I cannot understand.
Posted: Tue Aug 28, 2007 12:09 am
by ReDucTor
would help if you gave us the snippit of code thats not working.
Posted: Tue Aug 28, 2007 12:21 am
by rozvinbm_jp
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
[b]Javascript/AJAX code: ajax.js[/b]
[syntax="javascript"]var xmlHttp;
var m_placeholder;
function executeProcess(serverscriptfile, placeholder, fieldcode, posts) {
alert('ajax');
// line of codes for confirmation messages.
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
m_placeholder = placeholder;
var url=serverscriptfile;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=shift_jis');
xmlHttp.send(posts);
}
function stateChanged() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById(m_placeholder).innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject() {
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
HTML code to call the script:
Code: Select all
<input id="kensaku" name="kensaku" type="button" value="検索" style="width: 49px; height: 33px"
onclick="<?php echo "executeProcess('processes/pro" . $_SESSION['window'] . "', '" . $_SESSION['placeholder'] ."', '". $_SESSION['fieldcode'] ."', ". $_SESSION['posts'] ."+'&rowsperpage=5&pageidx=1&mode=kensaku' )"; ?>" />
PHP Code:[/syntax]
Code: Select all
<?php
header('Content-Type: text/html; charset=shift_jis');
session_start();
session_destroy(); // just need to reset my session vars
session_start();
$_SESSION['window'] = basename(__FILE__);
$_SESSION['placeholder'] = 'table';
$_SESSION['fieldcode'] = "shopcd";
$_SESSION['posts'] = "'shopcd=' + shopcd.value"
. "+'&shopname=' + shopname.value"
. "+'&keitaimail=' + keitaimail.value"
. "+'&keitaibangou=' + keitaibangou.value"
. "+'&email=' + email.value"
. "+'&fax=' + fax.value"
. "+'&shoppostcode=' + shoppostcode.value"
. "+'&choume=' + choume.value"
. "+'&banchi=' + banchi.value"
. "+'&ban=' + ban.value"
. "+'&heyamei=' + heyamei.value";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http:?//www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis">
<title>配達システムページ</title>
<SCRIPT type="text/javascript" src="<?php echo WORKINGSCRIPTS; ?>ajax.js" >
<!-- Beginning of JavaScript -
// - End of JavaScript - -->
</SCRIPT>
</head>
<body >
</body>
</html>
WORKINGSCRIPTS constant variable holds the absolute location of the scripts usign webroot. (
http://localhost/websites/delivery/scripts/ajax.js)
kensaku means search.
I'am using Zend Studio 5.0 for IDE.
PHP5.2.3
Apache2.2.4
WINDOWS XP Japanese OS
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Tue Aug 28, 2007 12:21 am
by rozvinbm_jp
duplicated
Posted: Tue Aug 28, 2007 1:01 am
by Kieran Huggins
whoa - you're making it hard on yourself!
Check out jQuery - an ajax call that writes the response to a div looks like this:
Code: Select all
$('div#updateMe').load('/path/to/ajax.php?jquery=awesome')
[/syntax]
Posted: Tue Aug 28, 2007 1:20 am
by rozvinbm_jp
Kieran Huggins wrote:whoa - you're making it hard on yourself!
Check out jQuery - an ajax call that writes the response to a div looks like this:
Code: Select all
$('div#updateMe').load('/path/to/ajax.php?jquery=awesome')
[/syntax]
It seems more simple to understand but I dont know how to implement that strategy.
Which part of the code?
ajax.php = is the php file called by the ajax. same as the
serverscriptfile parameter in the given javascript code.?
updateMe = is the
<div> id attribute?
Posted: Tue Aug 28, 2007 9:18 am
by Kieran Huggins
yup - you can get an overview of jquery at
http://jquery.com and I like to use
http://visualjquery.com as a quick reference to common functions.
Posted: Tue Aug 28, 2007 5:39 pm
by CoderGoblin
Jquery can look daunting at first glance, as can a lot of the javascript libraries out there. (Another one is called prototype but i tend to go with jquery). They do save time in the long run, especially if you can get plugins for them. Another useful thing about libraries is the maintenance aspect. Using a library avoid repetitive coding. If you are not careful, without them, you tend to have "duplicate" code all over the place. Changes to one piece are often not replicated as they should be.
As with a lot of things it's always a case of how long does it take to learn/implement and what are its advantages vs how long does it take to get things working now as well as maintain it.