Wordpress ajax未传递文本变量
我使用wordpress官方网站上的ajax代码。如果我发送数字,一切正常,如果我发送一个文本变量,它不会发送 如果我用数字更改文本,则所有内容都工作并存储在数据库中,如果我键入文本,则它将发送0 index.phpWordpress ajax未传递文本变量,ajax,wordpress,variables,text,send,Ajax,Wordpress,Variables,Text,Send,我使用wordpress官方网站上的ajax代码。如果我发送数字,一切正常,如果我发送一个文本变量,它不会发送 如果我用数字更改文本,则所有内容都工作并存储在数据库中,如果我键入文本,则它将发送0 index.php <?php add_action( 'admin_footer', 'my_action_javascript' ); // Write our JS below here function my_action_javascript() { ?> <sc
<?php
add_action( 'admin_footer', 'my_action_javascript' ); // Write our JS below here
function my_action_javascript() { ?>
<script type="text/javascript" >
jQuery(document).ready(function($) {
var data = {
'action': 'my_action',
'whatever': 12345,
'notes': sometext, / Text is not sent???
'courseid': 666555444
};
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
jQuery.post(ajaxurl, data, function(response) {
alert('Got this from the server: ' + response);
});
});
</script> <?php
}
jQuery(文档).ready(函数($){
风险值数据={
“行动”:“我的行动”,
“随便什么”:12345,
“备注”:sometext,/Text未发送???
“课程ID”:666555444
};
//因为2.8 ajaxurl总是在admin头中定义,并指向admin-ajax.php
post(ajaxurl、数据、函数(响应){
警报('从服务器获取此信息:'+响应);
});
});
代码的问题在于,您正在将$\u POST['notes']
中的字符串转换为整数:
$notes = intval( $_POST['notes'] );
只需删除对intval
的调用即可按预期获取字符串:
$notes = $_POST['notes'];
问题:如果notes
是字符串,为什么要将其转换为整数?:$notes=intval($\u POST['notes'])代码>我刚刚从wordpress页面复制了代码,谢谢,如何将评论标记为正确答案Hehyu不能:P我会在下面留下一个答案,这样你就可以将其标记为接受。
$notes = $_POST['notes'];