我假设文本文件的ID是url-field 这是JS代码
$("#url-field").keyup(function(event) {
var url_val=$("#url-field").val();
$.ajax({
type:"POST",
url: ajaxurl,
data: {
action:\'use_someprefix_update_url\',
search_string:url_val,
namefiled : namehere,
postid : postidhereYouCangetItIHope
},
success:function(data){
alert("Success, you can remove me :-) ");
}
});
});
PHP来了,把它放在函数中。php
function use_someprefix_update_url(){
$defaults = array();
$defaults[ $_POST[\'namefiled\'] ] = array (
\'name\' => $_POST[\'namefiled\'],
\'value\' => $_POST[\'search_string\'],
);
update_post_meta( $_POST[\'postid\'] , \'_product_attributes\', $defaults );
}
此外,该挂钩还:
add_action(\'wp_ajax_use_someprefix_update_url\', \'use_someprefix_update_url\');
附言:你必须做验证工作。