javascript - Nginx - admin-ajax.php - ajax result return issue - wordpress causing Uncaught SyntaxError: Unexpected token < -
the problem works ok on apache. nginx returns error uncaught syntaxerror: unexpected token <
here function functions.php
function searchranges() { global $wpdb;
if (strlen($_post['s'])>0) { $postid = $_post['s']; $args = array( 'numberposts' => 5, 'post_type' => array ( 'mail'), 's' => $postid ); // results $the_query = new wp_query( $args ); $array = array(); $i = 0; if( $the_query->have_posts() ): while ( $the_query->have_posts() ) : $the_query->the_post(); $array[$i] = array(); $array[$i]['title'] = get_the_title(); $array[$i]['permalink'] = get_permalink(); $trendingrows = get_field('mail_name') ?: get_field('mail_colo') ?: get_field('mail_lamo') ?: get_field('mail_rug') ?: get_field('mail_ti') ?: get_field('mail_timb') ?: get_field('mail_vin'); if($trendingrows) { $ti =1; foreach($trendingrows $rowinttv) { if ($ti==1) { fetch data function } } } $array[$i]['mailtype']= get_field('carp_mail_type'); $i++; endwhile; echo json_encode($array); endif; } else echo ''; die();
my scripts.js looks this
$( "#rangesearch" ).autocomplete({ minlength: 3, source: function(request, response) { $.ajax({ url: "/wp-admin/admin-ajax.php", data: 'action=fm_searchranges&s=' + $("#rangesearch").val(), datatype: "json", type: "post", success: function(data) { $("#search_by_results").html(""); $("#search_by_results").show(); (var = 0; < data.length; i++) { console.log(data[i]['fibretype']); $("#search_by_results").append('<div class="sbr_row"><img src="/images'+ data[i]['image'].replace('"', '') +'" alt="" /><h2>'+ data[i]['title'] +'</h2><h3>'+ data[i]['type'] +'</h3><a href="'+ data[i]['permalink'] +'">view mail</a></div><!--.row-->'); } } }); } }).data( "autocomplete" )._renderitem = function( ul, item ) { return $("<li></li>") .data("item.autocomplete", item) .append("<a>" + item.label + "<br>" + item.description + "</a>") .appendto(ul); }; })
ok.
we had autocomplete.min.js inserted code causing issues/conflict , admin-ajax.php post action inaccessible.
turned off automcomplete , seems work now.
Comments
Post a Comment