Thanks for your answers. I'm pretty sure my ajax call is done, thanks
to firebug (which is great by the way) and a few 'alert'. I suspected
extra white space (I must try a javascript trim...) at the end of my
string, I'll try JSON (must learn about it before). Great idea to
return an array too, with several identified chunks of data, it should
be handy for me. By the way, do you know good links about constructing
'heavily ajaxed' applications, managing and formatting data ? I'll
soon have to deal with this kind of project. But first JSON and
arrays...

thx again
Flo

On Sep 23, 11:42 pm, "morris...@ingenious.org"
<morris...@ingenious.org> wrote:
> Flo,
>
> I would suggest using $.getJSON() instead of the straight $.get() if
> you have the json_encode function available to you (PHP 5.2.x+ should
> have this). This is because you may have some extra white space at the
> end of what you are returning now.
>
> in your php do this
>
> <?php
> echo json_encode(array('success' => 'ok'));
> ?>
>
> in js do this
>
> $.getJSON("phpfile.php", {param:param...}, function(data) {
>      if(data.success == 'ok') {
>
>      }
>
> });
>
> Chris
>
> On Sep 23, 11:24 am, Florian Motteau <fmott...@gmail.com> wrote:
>
> > Hi all,
>
> > I've been working with jQuery for a few weeks now (still a noob so :), and
> > I'm a bit confused about getting information from a php file. Basically :
>
> > MY JAVASCRIPT FILE:
> > $.get("phpfile.php", {param:param...}, function(data) {
>
> >   if(data == "ok") {
> >     ...do stuff...
> >   }
>
> > })
>
> > MY PHP FILE:
> > <?php
> > echo "ok";
> > ?>
>
> > In this dumb example, I'm unable to match the 'data' returned variable with
> > the value I assigned to it in php (I can't manage to enter my 'do stuff'),
> > yet its value is 'ok' if I display it. I have no problem to retrieve html
> > code from php and inject it in my pages, but I can't test it as a regular
> > javascript string.
>
> > What's wrong in this ? What have I missed about the 'data' format ? Do I
> > have to 'cast' data to a javascript string (and if so, how ?) ?
>
> > And finally, sorry about my english, I'm french :-)
>
> > thanks
> > Flo

Reply via email to