Jump to content

New to Ajax (Dumb question ?)


mwl707

Recommended Posts

Hi I bought an Ajax book and am nearly half way thru. I have at this point managed to get text from the server and into my web page. My question is ,I know I can query a php file on the server but can Ajax allow me to return variables and such back to my web page - not just a piece of text?. for example can I find out if a customer exists on my database etc.

I am not looking for code examples just if I should keep reading the book - or is Ajax not going to help me in this instance ?

Thanks for any comments , Mick  :confused:

Link to comment
https://forums.phpfreaks.com/topic/169439-new-to-ajax-dumb-question/
Share on other sites

My question is ,I know I can query a php file on the server but can Ajax allow me to return variables and such back to my web page - not just a piece of text?. for example can I find out if a customer exists on my database etc.

Basicly what you do with Ajax is call a php script(or any other serverside script) without refreshing the page main. So you can indeed find out if a customer exists in your database. I don't get how returning a piece of text is not helpfull though, what exactly do you mean with return variables? Also how do you wish to check if a user does exist or not? Do you want to use a form?

 

 

I am not looking for code examples just if I should keep reading the book - or is Ajax not going to help me in this instance ?

Thanks for any comments , Mick  :confused:

Well code examples are usually the best way to explain but I guess it can be explained with the following

 

Mainpage.html                                              ajax_check_user_exist.php

 

---------------------------------      name        -------------------------

|  customename:                      |      -->          |                                |

|                                            |                      -------------------------

|      -----------------            |      yes/no

|      |                      |            |      <--

|      -----------------            |

|                                            |

---------------------------------

 

 

In the above example is a form on a html page. Using ajax (XMLHttpRequest)  a name gets send to ajax_check_user_exist.php script. The php script returns either yes or no here.

On your Mainpage.html you can display this text.

Thanks for your help. I understand what you are describing but it seems all I can do with the response from the server is display it. What I would hope to do is get the response (Ie CustomerExists = "true") and then continue with the browser script say for instance

if (customerExists == "true") { call function etc };

I hope this makes sense and as I said this is just random code, I just can't get how to use the data returned to the browser ?

 

Thanks Mick

Thanks for your help. I understand what you are describing but it seems all I can do with the response from the server is display it.

No you can do more with it then just display it.

 

What I would hope to do is get the response (Ie CustomerExists = "true") and then continue with the browser script say for instance

if (customerExists == "true") { call function etc };

I hope this makes sense and as I said this is just random code, I just can't get how to use the data returned to the browser ?

 

Thanks Mick

Yes that does makes sence and that is exacly what you can do with the text returned. Also this is where code would be more explanitory instead of a description of your problem.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.