Reputation: 3424
var form_data = {
username: $("#username").val(),
password: $("#password").val(),
is_ajax: 1
};
$.ajax({
type: "POST",
url: action,
data: form_data,
success: function(response) {
if (response==username) {
I want to access username variable that i have declared in form_data variable. How can i? i am using $("#username").val() but i want to access the variable.
Upvotes: 1
Views: 224
Reputation: 10537
form_data.username
is the variable you want
if (response == form_data.username) {
so in result, it will all look like
var form_data = {
username: $("#username").val(),
password: $("#password").val(),
is_ajax: 1
};
$.ajax({
type: "POST",
url: action,
data: form_data,
success: function(response) {
if (response == form_data.username) {
Upvotes: 1
Reputation: 600
var form_data = {
username: $("#username").val(),
password: $("#password").val(),
is_ajax: 1
};
$.ajax({
type: "POST",
url: action,
data: form_data,
success: function(response) {
if (response==form_data.username) {
Upvotes: 2