During production the AJAX result from xmlHttp.responseText

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
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

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Is your post in reference to another of your threads, a new problem, or is it merely a random statement?
rozvinbm_jp
Forum Commoner
Posts: 43
Joined: Thu Jun 14, 2007 8:36 pm
Location: Fuji-shi, Shizuoka-ken, Japan

Post 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.
ReDucTor
Forum Commoner
Posts: 90
Joined: Thu Aug 15, 2002 6:13 am

Post by ReDucTor »

would help if you gave us the snippit of code thats not working.
rozvinbm_jp
Forum Commoner
Posts: 43
Joined: Thu Jun 14, 2007 8:36 pm
Location: Fuji-shi, Shizuoka-ken, Japan

Post by rozvinbm_jp »

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;
}
HTML code to call the script:

Code: Select all

                 <input id="kensaku" name="kensaku" type="button" value="&#26908;&#32034;" 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>&#37197;&#36948;&#12471;&#12473;&#12486;&#12512;&#12506;&#12540;&#12472;</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

,

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

Post by rozvinbm_jp »

duplicated
Last edited by rozvinbm_jp on Tue Aug 28, 2007 1:14 am, edited 1 time in total.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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]
rozvinbm_jp
Forum Commoner
Posts: 43
Joined: Thu Jun 14, 2007 8:36 pm
Location: Fuji-shi, Shizuoka-ken, Japan

Post 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?
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
Post Reply