views:

51

answers:

2

I need to call the server AJAX-way, just to get 1 parameter:

Must I do this through JSON? Or, can I just shoot this through like a regular HTML page, like this:

4

or

6

Then, will JavaScript be able to read that line? If so, how can I do this using jQuery?

+1  A: 

No you don't have to use JSON, you can return plain text to your AJAX requests if you want.

$.get (
    'your_script',
    {
        // parameters
    },
    function ( response ) {
        // whatever you return on the server will be in the response variable
    }
);
Jan Hančič
I'm currently returning HTML and replacing a div. Very handy :-)
Topher Fangio
+1  A: 

You may use jQuery.ajax:

$.ajax({
  url: "foo.php",
  success: function(msg){
    alert(msg); // alerts 4 or 6
  }
});
moff
IMO, `$.get` should be preferred over `$.ajax` unless you need lower level access to the call. For a simple call like this, `$.get` is a good choice: `$.get("foo.php", function(msg){ alert(msg) });`
Doug Neiner