During production the AJAX result from xmlHttp.responseText
Moderator: General Moderators
-
rozvinbm_jp
- Forum Commoner
- Posts: 43
- Joined: Thu Jun 14, 2007 8:36 pm
- Location: Fuji-shi, Shizuoka-ken, Japan
During production the AJAX result from xmlHttp.responseText
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.
I added an alert in order to check if the script was called. The alert was displayed.
-
rozvinbm_jp
- Forum Commoner
- Posts: 43
- Joined: Thu Jun 14, 2007 8:36 pm
- Location: Fuji-shi, Shizuoka-ken, Japan
-
rozvinbm_jp
- Forum Commoner
- Posts: 43
- Joined: Thu Jun 14, 2007 8:36 pm
- Location: Fuji-shi, Shizuoka-ken, Japan
feyd | Please use
HTML code to call the script:
PHP Code:[/syntax]
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
,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;
}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' )"; ?>" />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>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
,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]-
rozvinbm_jp
- Forum Commoner
- Posts: 43
- Joined: Thu Jun 14, 2007 8:36 pm
- Location: Fuji-shi, Shizuoka-ken, Japan
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
whoa - you're making it hard on yourself!
Check out jQuery - an ajax call that writes the response to a div looks like this:
[/syntax]
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')-
rozvinbm_jp
- Forum Commoner
- Posts: 43
- Joined: Thu Jun 14, 2007 8:36 pm
- Location: Fuji-shi, Shizuoka-ken, Japan
It seems more simple to understand but I dont know how to implement that strategy.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:
[/syntax]Code: Select all
$('div#updateMe').load('/path/to/ajax.php?jquery=awesome')
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?
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
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.
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
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.
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.