user782400
user782400

Reputation: 1737

Read GET and POST variables from forms

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.

Upvotes: 0

Views: 1182

Answers (2)

peterjwest
peterjwest

Reputation: 4452

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.

Upvotes: 1

mckoch
mckoch

Reputation: 330

Try

console.log($('form').serialize());

Upvotes: 0

Related Questions