In case anyone's interested... I got it to work using this: http://www.tizag.com/ajaxTutorial/ajaxxmlhttprequest.php
Thanks everyone for your suggestions. I will break down and learn jQuery soon. (So using jQuery is as simple as calling a library from google? cool.) I promise. Merrill On Wed, Mar 9, 2011 at 5:46 PM, Aaron Luman <[email protected]> wrote: > To get it to work (in the meantime): > > in your header: > > <script > src="//ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script> > > then, the entirety of your ajax call is: > > $.get('*php_file*' > , function(data) > { > $(my_dvd).html(data); > }); > > Aaron > > On Mar 9, 2011, at 4:05 PM, Merrill Oveson wrote: > >> yes, I've tested the php function. It displays on the screen when the >> ajax calls it. >> >> What do you mean caught by the ajax function? >> >> Here's my javascript: >> var url = 'sale_edit_ajax_package_price.php?packageId=' + packageId + '&'; >> var answer = getServerText(url,'a'); >> alert ("answer is " + answer); >> >> How do I get answer to receive the result from my php file? >> >> I know I need to learn jQuery. I plan on it. In the meantime, I need >> to get this working. >> >> Thanks >> >> On Wed, Mar 9, 2011 at 4:57 PM, Aaron Luman <[email protected]> wrote: >>> Anything that your pop script echos will be caught by the ajax function. >>> Have you tested the php by itself? >>> >>> Also, if you plan on running any level of interactivity on your site I would >>> suggest that you use something like jQuery as it greatly simplifies stuff >>> like this. >>> On Mar 9, 2011 3:36 PM, "Merrill Oveson" <[email protected]> wrote: >>>> Uphpers: >>>> >>>>> From javascript I launch a php script via ajax. >>>> so far so good. >>>> >>>> the php script produces one single value. >>>> >>>> how do I get this value back to javascript? >>>> >>>> Here's my ajax: >>>> >>>> function getServerText(myurl,div_id) { >>>> var http = getXMLHTTPRequest(); >>>> //alert ("php file is " + myurl); >>>> //alert ("div_id is " + div_id); >>>> myRand = parseInt(Math.random()*99999999999999999999999999999); >>>> var modurl = myurl+"rand="+myRand; >>>> http.open("GET", modurl, true); >>>> //alert ("readystate is " + http.readyState); >>>> http.onreadystatechange = function() { >>>> //alert ("div_id is " + div_id); >>>> if (http.readyState == 4) { >>>> if (http.status == 200) { >>>> var mytext = http.responseText; >>>> document.getElementById(div_id).innerHTML = mytext; >>>> } >>>> } else { >>>> //document.getElementById(div_id).innerHTML = 'please wait'; >>>> //Remember your actually in the directory that launches >>>> ajax.js not the includes directory! >>>> document.getElementById(div_id).innerHTML = '<img >>>> src="images/anim.gif">'; >>>> } >>>> } >>>> http.send(null); >>>> } >>>> >>>> >>>> here's my javascript: >>>> >>>> var answer = getServerText(url,'a'); >>>> >>>> //answer ends up undefined. >>>> >>>> php: >>>> >>>> I've tried echo and return - no love. >>>> >>>> Someone suggested JSON. I only have one value so this seems like >>>> overkill. Or do I have to use JSON? >>>> If so, do I create the JSON object in the php, then echo it? >>>> >>>> Is there something wrong with my ajax script? >>>> >>>> Thanks >>>> >>>> Merrill >>>> >>>> _______________________________________________ >>>> >>>> UPHPU mailing list >>>> [email protected] >>>> http://uphpu.org/mailman/listinfo/uphpu >>>> IRC: #uphpu on irc.freenode.net >>> >>> _______________________________________________ >>> >>> UPHPU mailing list >>> [email protected] >>> http://uphpu.org/mailman/listinfo/uphpu >>> IRC: #uphpu on irc.freenode.net >>> > > > _______________________________________________ > > UPHPU mailing list > [email protected] > http://uphpu.org/mailman/listinfo/uphpu > IRC: #uphpu on irc.freenode.net > _______________________________________________ UPHPU mailing list [email protected] http://uphpu.org/mailman/listinfo/uphpu IRC: #uphpu on irc.freenode.net
