开发者

Read GET and POST variables from forms

开发者 https://www.devze.com 2023-03-22 08:39 出处:网络
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.

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开发者_StackOverflow社区.


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.


Try

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号