0

I want to know how can we read the GET and POST variables from forms using jQuery and then later display then in the console log in chrome.

This is similar to what Firebug does.

user782400
  • 1,617
  • 7
  • 30
  • 51

2 Answers2

1

Are you aware that you can already view these variables in the console, by looking at the network tab?

If you want them within javascript, for the GET variables you can use a simple script to get these from the URL:

var params = (window.location.href.split("?")[1] || "").split("&");
var get = {};
$.map(params, function(p) { get[p.split("=")[0]] = p.split("=")[1]; });
console.log(get);

This will give you a hash of the GET variables.

There is already a very good (better) solution for this here: how to get GET and POST variables with JQuery?

Unfortunately Javascript doesn't have access to the POST variables sent to the page, you would have to use a server side language to output them as JSON.

Community
  • 1
  • 1
peterjwest
  • 4,294
  • 2
  • 33
  • 46
  • yes, I do know but since I am learning about jQuery and HTTP request; I would like to develop something by myself too – user782400 Jul 24 '11 at 15:14
0

Try

console.log($('form').serialize());
mckoch
  • 330
  • 1
  • 4
  • just like that or should I include any URL too ? – user782400 Jul 24 '11 at 18:54
  • Oops, thought you were looking for a possibility to construct a querystring from forms. Parsing the current documents URL can be done easly with Michael Mannings plugin from http://plugins.jquery.com/files/jquery.parsequery.js.txt – mckoch Jul 28 '11 at 17:02