我在WordPress页面上使用jQuery的帖子.
var thename = jQuery("input#name").val();
jQuery.post(the_ajax_script.ajaxurl, jQuery("#theForm").serialize(),
function(response_from_the_action_function){
jQuery("#response_area").html(response_from_the_action_function);
});
Run Code Online (Sandbox Code Playgroud)
它发布表单中的选择.是否可以将数据附加到帖子中.所以除了表单数据之外,我还需要在jQuery帖子中添加几个lat long.我怎样才能做到这一点.可能吗?
骗过你
-Laxmidi
.post()将字符串作为第二个参数,因此您可以使用+后跟字符串连接自定义字符串.
var thename = jQuery("input#name").val();
jQuery.post(the_ajax_script.ajaxurl, jQuery("#theForm").serialize() + "&foo=bar",
function(response_from_the_action_function){
jQuery("#response_area").html(response_from_the_action_function);
});
Run Code Online (Sandbox Code Playgroud)
但要小心; 字符串必须正确格式化为URL,因此您需要key=value以&s 分隔的对.
在上面的例子中,你会看到+ "&foo=bar.第一个&完成由最后创建的值.serialize(),然后foo=是一个键,后跟bar值.
如果您想在之后添加更多值,可以执行以下操作:
&foo=bar&baz=zip
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3002 次 |
| 最近记录: |