I really think you should read through the examples given under the ajax()
documentation, and the tutorials available on Ajax (and possibly some of the
others too) - look for Tutorials on the jQuery website Documentation page.

The ajax() examples show you what needs to go in your calling program
(presumably test.php), and I've already explained one way to get php to
return data (HTML or JSON).

The 'block' is simply the JSON structure that the success handler would see
in my particular example.
Is it complete? You can see it is by comparing it to what my example php
code echoed. For what you might want to do, who knows.


Tek7 wrote:
> 
> Thanks for getting back to me. Sorry to be a pest...:
> 
> you mentioned:
> Then tell $.ajax that it is expecting JSON data, and the success handler
> will receive data as on object... 
>   { ok: true 
>   , data: { sessionId: '12345ABCD6789' 
>              , progName: 'AjaxHandler.php' 
>              , from: 'Wizzud' 
>              } 
>   } 
> 
> 
> 
> Where does this above block go? And is that complete or would I need to
> add more to it?
> Just to elaborate a little more, I have a file called test.php, and
> another file called ajaxhandler.php
> In ajaxhandler.php I only need to do my echo: echo "<div
> id='ajaxOne'>Hello World, from $myName</div>"; 
> 
> and what exactly would I do in test.php? 
> Actually is it possible I could see a small sample of interaction between
> two php pages, just displaying regular html data? Just like 'hello world'
> being processed from one php page to another
> Thanks again,
> Mike
> 
> 
> 
> 
> Wizzud wrote:
>> 
>> Your php program simply 'echo's its data. That data can be HTML, XML,
>> JSON, etc, but whatever it is the $.ajax call needs to be aware of the
>> type of data expected to be returned (dataType), and it can then inspect
>> the returned data in its success handler and, if necessary, act on it.
>> 
>> Example (very simple!):
>> /*
>> * AjaxHandler.php
>> */
>> <?php
>> $myName = $_SERVER['PHP_SELF'];
>> echo "<div id='ajaxOne'>Hello World, from $myName</div>";
>> ?>
>> 
>> In the success handler the data is the String...
>> "<div id='ajaxOne'>Hello World, from AjaxHandler.php</div>"
>> ... which can then be appended/prepended to body, or manipulated using
>> String techniques, or ignored completely, or whatever you wish to do with
>> it.
>> 
>> If you want to return JSON data from AjaxHandler.php simply echo it (this
>> is over-simplified but still...) ...
>> echo "{ok: true, data{sessionId: '$phpSessionId', progName:
>> 'AjaxHandler.php', from: 'Wizzud'}}";
>> 
>> Then tell $.ajax that it is expecting JSON data, and the success handler
>> will receive data as on object...
>>   { ok: true
>>   , data: { sessionId: '12345ABCD6789'
>>              , progName: 'AjaxHandler.php'
>>              , from: 'Wizzud'
>>              }
>>   }
>> 
>> From within your success handler you can do what you like with that data,
>> eg ....
>> .....
>> dataType:'json',
>> success:function(json){
>>   if(json.ok){
>>     $('#myHeader').text(json.data.from);
>>   }
>> },
>> .....
>> 
>> HTH.
>> 
>> 
>> Tek7 wrote:
>>> 
>>> Hello all,
>>> 
>>> I apologize as i'm sure I could discern this within the forums, but
>>> after much looking i've had a little difficulty understanding. I think
>>> once I push past this confusion i'll be able to go forward with
>>> everything else:
>>> 
>>> 
>>> How on earth can I grab data from a php page within my jquery? To be
>>> more specific, here is a small block of code I had, (just a snippet
>>> nestled between script tags):
>>> 
>>> 
>>>  function test() { 
>>>         $.ajax({
>>>                 url: 'AjaxHandler.php?a=' + document.forms[0].txt.value,
>>>                 success: XXXXXXXXXX
>>>               });                                   
>>>     } 
>>> 
>>> So let's assume I want to call load ajaxhandler.php, pass in the
>>> variable a, examine the var in ajaxhandler.php, and output some text as
>>> a result of what was passed. On success, I want to call some function in
>>> XXXXXXXXXX and have it alter the inner html of a div on the page. I want
>>> the inner html to be altered based on php session data (or a message
>>> returned from ajaxhandler.php, let's say. i don't care which). How do i
>>> get the data? I'm a little confused how php sends data back.
>>> 
>>> Thanks so much for shedding light,
>>> 
>>> Mike
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/newbie-question-tf4446564s15494.html#a12694866
Sent from the JQuery mailing list archive at Nabble.com.

Reply via email to