PDA

View Full Version : [Ext Core 3.0] unterminated string literal



Mycoding
8 May 2011, 7:05 AM
Please help me to solve this.
I write site on Ext Core and have such bug.



Ext.Ajax.request({
method:'POST',
params:{
action:parsedUrl[0],
name:parsedUrl[1]
},
url: 'request/get-data.php',
success: function(response, opts){
var obj = Ext.decode(response.responseText);// Error occur here
}
});


Ajax get this text from server


{success:true,responce:{title:"3D",text:"Наконец то разобрался, вот пример (открывать в мозиле)
<a href='http://moc-081.narod.ru/data/3d/1.html'>
3d линия</a><br>.
Так же гляньте вот это <a href='http://dxdy.ru/topic25636.html'> Форум dxdy.ru</a>"}}


Error this

unterminated string literal

Help me to fix it,please.

kendoctor
8 May 2011, 5:22 PM
1: your client html page character code is ? and your character server code is ? if all are utf-8, will be better.
2: json parse use strictly defined will be better, { a:1 } not good, {"a":"1"} will be better

Mycoding
8 May 2011, 8:56 PM
The main bug was in so that from server text is sending.
And in text there are not visible '\n' '\r'


$strToEcho = "{success:true,responce:$this->response}";
$strToEcho = str_replace(array("\r", "\n"), '', $strToEcho);
echo $strToEcho;



And also I have to replace ' -caracters on " in reference


$title = str_replace(array("'"), '"', $row['title']);
$text = str_replace(array("'") , '"', $row['text']);
$this->response .="{".
"title:'".$title.
"',text:'".$text.
"'}";


Actioly I was very suprused of this non-working occasion.
I work with ExtJS from January of 2010 and I have never faced this bug.
Maybe in ExtJS it is solved.
I mean non-visual \n and \r are being replaced.
But in Ext Core not.

kendoctor
8 May 2011, 11:03 PM
why not to use json_encode function in PHP!!!

Mycoding
8 May 2011, 11:42 PM
About json_encode.
I have some problem with Russian, and also it encode all properties.
But I used to work with text in charset "windows-1251"
Now I use utf-8 maybe in it there is not such problem.
I will try.

Thanks for answer.

So I usually do like this


while($row = mysql_fetch_assoc($rs)){
$parsed_text='';
$p = explode(";", $row['text']);
for($i=0;$i<count($p)-1;$i++){
$field_value = explode("=", $p[$i]);
$parsed_text.=$field_value[0].":".$field_value[1].',';
}
$parsed_text[strlen($parsed_text)-1]=" ";

$this->rows_str_json.="{".
"id:'".$row['id'].
"',webmaster_id:'".$row['webmaster_id'].
"',reklamodatel_id:'".$row['reklamodatel_id'].
"',date:'".$row['date'].
"',status:'".$row['status'].
"',check:'".$row['check'].
"',ip:'".$row['ip'].
"',url:'".$row['url'].
"',company:'".$row['company'].
"',comment:'".$row['comment'].
"',sid:'".$row['sid'].
"',".$parsed_text.
"},";
}