开发者

how to pass variable in using post method with jquery .load()

I want to pass the variables name, email into the .load() event.

var email = $('#reg-email').val();
var name = $('#reg-name').val();
$("#user-detail").load("proc/reg-step2.php",{ "name": "name" , "email": "email" }, function() {
    $("#ajaxLoader2").re开发者_运维问答move();
});

What should be the syntax for this section so that the variable is passed instead of jst the strings I've written here { "name": "name" , "email": "email" }??


You can use a variable instead of a literal: { "name": name, "email": email }


In an object literal you can use quotation marks around the property names, but you shouldn't use them around the variable names that you use in the values:

{ "name": name, "email": email }

You can also write the object literal without quotation marks around the property names:

{ name: name, email: email }

You can also mix quoted and unquoted property names, as you need:

{ "name": name, email: email }

If you would have a property name with special characters, like name+email, you need quotes around it in the object literal:

{ "name+email": name + ', ' + email }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜