php - How to remove array boundary quotes in jquery? -


i have ajax call respond comma separated values. want change value array.

here example

$.ajax  ({                   url: url,       type: 'post',       data: data,       success: function(response)      {          console.log([response]);        } }); 

in response

'alappuzha','beypur','cheruvannur','edakkara','edathala','kalamassery'  

like this

i converting array [response] shows

["'alappuzha','beypur','cheruvannur','edakkara','edathala','kalamassery'"] 

like

but don't want boundary quotes

here php code

foreach($citydata $keyrow):      $citylist[]= "'".$keyrow['location_name']."'";   endforeach;  $datacity = implode(",",$citylist);  print($datacity); exit; 

thank in advance

the correct solution fix in server side , return proper string array client.

if not possible, can split string , process each item , remove starting , ending '

var response = "'alappuzha','beypur','cheruvannur','edakkara','edathala','kalamassery'";  var array = response.split(',').map(function(value) {    return value.replace(/^'|'$/g, '')  });  snippet.log(json.stringify(array));
<!-- provides `snippet` object, see http://meta.stackexchange.com/a/242144/134069 -->  <script src="http://tjcrowder.github.io/simple-snippets-console/snippet.js"></script>


with php

foreach($citydata $keyrow):      $citylist[]= $keyrow['location_name'];   endforeach;  print(json_encode($datacity)); exit; 

then use response is

$.ajax({   url: url,   type: 'post',   data: data,   datatype: 'json',   success: function(response) {     console.log(response);   } }); 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -