0

i am going to try the jQuery code:

$.post("test.php", { category: "Ubuntu", newname: "Hash" },

function(data) {
     alert("Data Loaded: " + data);
   });

but in json data i want to use some data taken from a formfield. i used to grab the data using getElementById('fieldname').value. How to pass variable to json query ?

3

2 Answers 2

1
var category = $('#fieldname1').val(), // just assume id with fieldname1, fieldname2 etc
    newname =  $('#fieldname2').val();

$.post("test.php", { category:category , newname: newname  },

function(data) {
     alert("Data Loaded: " + data);
   });
Sign up to request clarification or add additional context in comments.

Comments

0

We can post anything in jquery as

var cat = $('#cat').val(),//for taking category value
    name =  $('#new').val();//for taking newname value
$.post("test.php", { category:cat , newname: name  },function(data) {
     alert("Data that came from server : " + data);
});

You can access the variables in server as category and newname as the variables. Access them and then return the data you want.Your returned data comes to the variable data of the callback function().

Here we accessed the values of the textboxes with id as cat and new.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.