JQuery ajax post post issue
I've been looking for an answer for a while, I want to be able to parameterize the values โโof my AJAX plugins. So, for example, rather than:
$.post('test.aspx', { name: 'bob' }, function(data){
....
});
I want to parameterize the name and value used in the message, for example
var var1 = 'name';
var var2 = 'bob';
$.post('test.aspx', { var1: var2 }, function(data){
....
});
My problem is that it inserts the value "bob" but posts it as "var1" and not "name". And on the server side, it expects a name not var1.
Does anyone have any idea?
+2
source to share
2 answers
This works for me:
$(document).ready(function()
{
var var1 = "bobsname";
var var2 = "bob";
ajax(var1, var2)
function ajax(name, variable)
{
$.ajax(
{
type: "POST",
data: name + "=" + variable,
url: "action.php",
success: function(html)
{
alert(html);
}
});
}
});
Im using ajax function .
0
source to share