Javascript 为ajax请求发送的Html格式无效
我试图在将html格式发送到ajax请求之前获取它。但是发生了如下错误:Javascript 为ajax请求发送的Html格式无效,javascript,php,jquery,ajax,wordpress,Javascript,Php,Jquery,Ajax,Wordpress,我试图在将html格式发送到ajax请求之前获取它。但是发生了如下错误:错误:SyntaxError:Unexpected tokenname'; } …或者根据WordPress Codex文档所需的任何内容。什么是var_dump($results)say?如何获取?我需要将结果发送到ajax请求如果您将结果发送到ajax请求,请直接在客户端代码中输入ajax请求,放入console.log(result)然后检查控制台中的输出。是的,我得到这个:object{suces:true,htm
错误:SyntaxError:Unexpected token<-parserrror-[object]
我只想通过数组中的值来选择选项。下面是代码:
$args = array(
'type' => 'ad_listing',
'child_of' => $parent_cat,
'orderby' => 'name',
'order' => 'ASC',
// 'hide_empty' => 1,
// 'hierarchical'=> 1,
'exclude' => '',
'include' => '',
'number' => '',
'taxonomy' => 'ad_cat',
'pad_counts' => false
);
$results = get_categories( $args );
$result = '<select>';
foreach ($results as $key => $value) {
$result .= '<option>' . $value . '</option>';
}
return $result .= '</select>';
// return the result to the ajax post
die( json_encode( array( 'success' => true, 'html' => $result ) ) );
我肯定我做错了什么:(因为我假设这是一个WordPress问题,get\u categories返回一个对象数组() 请执行以下操作:
foreach($results as $cat) {
$result .= '<option>'.$cat->name.'</option>';
}
foreach($cat结果){
$result.=''.$cat->name';
}
…或者根据WordPress Codex文档所需的任何内容。什么是
var_dump($results)
say?如何获取?我需要将结果发送到ajax请求如果您将结果发送到ajax请求,请直接在客户端代码中输入ajax请求,放入console.log(result)然后检查控制台中的输出。是的,我得到这个:object{suces:true,html:object}
它返回未找到的类别检查$args。如果未找到任何类别,则您的参数很可能有问题,或者没有与指定参数匹配的类别?但是当我在控制台中得到结果时,我在对象中得到类别
$results应该是一个对象。$results中的每个对象都应该有键和值?选择类别后,您可以从这里获得控制台结果:
foreach($results as $cat) {
$result .= '<option>'.$cat->name.'</option>';
}