Jump to content
dustcomposer

PHP get data value from ajax

Recommended Posts

Hi, what is the 'q' thing in this PHP AJAX tutorial: http://www.w3schools.com/php/php_ajax_php.asp :

 

HTML page:

xmlhttp.open("GET","gethint.php?q="+str,true);

 

PHP file:

$q=$_REQUEST["q"];

 

And how PHP read value of an input element (html) to be processed?

The same question if using jquery AJAX..

 

I'm learning XMLHttpRequest and trying to figure out how PHP get data value from HTML element to be processed. I don't know anything about PHP, I've just started a start.

 

Thanks!

 

Share this post


Link to post
Share on other sites

In order to learn AJAX it's recommended that you study PHP first. You won't be able to understand what's happening if you don't know PHP.

 

What you're asking about is a query string. It's used to send information to the server. PHP handles it using $_GET, $_POST and $_REQUEST variables. Read about it here: http://www.w3schools.com/php/php_forms.asp

 

$_REQUEST has data from GET, POST and COOKIE requests, which means people could use it to send data to your site in a way you didn't want them to, so I don't recommend using $_REQUEST.

Share this post


Link to post
Share on other sites

I'm focusing on the XMLHttpRequest.

 

I was looking for a method to 'Save/Open' file contains values of html elements, and then I found that XMLHttpRequest is a good one for me, like in this tutorial: http://www.w3schools.com/json/json_http.asp.

I create a simple simulation as follows:

  1. User modify values of html elements on the web page (Input values, innerHTML, CSS, etc.).
  2. They can save the new values as a .txt file containing array (json). I create a string as json format template, user can copy them and save it with Notepad as .txt on their PC.
  3. They're going to need to upload the .txt file to our server (I guess this one will need PHP).
  4. Using XMLHttpRequest, as in the tutorial, user can 'open' the web page with 'saved' values from their .txt file.

I tested this by upload my own array .txt and 'open' them using XMLHttpRequest, the web page updated with new values for its elements, it looks good for now. Just like AJAX intro says 'AJAX is about updating parts of a web page, without reloading the whole page.'.

 

And as for the PHP, I think I'm going to need a classroom to learn them, but thanks for the lesson.

Share this post


Link to post
Share on other sites

You can use AJAX to load information from a text file. In that case you won't need the "&q=" part.

 

If you are curious about query strings you do have to learn PHP.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...