CodeIgniter Forums
CI returns invisible symbol string to jquery ajax - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: CI returns invisible symbol string to jquery ajax (/showthread.php?tid=37322)



CI returns invisible symbol string to jquery ajax - El Forum - 01-05-2011

[eluser]Edgars[/eluser]
Don't know if It's Jquery or CI, but I have a situation.
I have simple controller with function
Code:
function eds (){    
           echo "edgars";
           }
And I have html file with javascript and Jquery ajax in it.
Code:
function eds (){

    $.ajax({
        url: '/index.php/hangman_controller/eds',
        success: function(data) {
here is alert with data length. forums doesnt allow sumbit it        
            }
        });
}
Everything works fine but alert is not returning 6 but 9. All those empty chars is in front of string. alert(data[0]), alert(data[1]), alert(data[2]) return nothing. after that 3, 4 it goes as it should.
I checked length in CI before sending it to AJAX and it was correct.


CI returns invisible symbol string to jquery ajax - El Forum - 01-05-2011

[eluser]Nick_MyShuitings[/eluser]
Have you tested in Firebug to see the response to the AJAX? That might be a good indicator. I was unable to reproduce in a test just now.


CI returns invisible symbol string to jquery ajax - El Forum - 01-06-2011

[eluser]Edgars[/eluser]
When I remove
Code:
$this->lang->load("language", "ENG");
I get correct length and AJAx response is ok - "eds". If that something means then header have Content-Length 6

With
Code:
$this->lang->load("language", "ENG");
I don't get correct length and AJAx response is still ok - "eds". ". Header Content-Length 9

Can't understand what is has to do with language? Maybe It's just coincidence.


CI returns invisible symbol string to jquery ajax - El Forum - 01-06-2011

[eluser]Nick_MyShuitings[/eluser]
Give this a try: Try returning the information json_encoded. Not only does it allow your javascript to be a bit more flexible should you change things in the future, but it might take care of this issue.

It'll get you in the better habit or returning a data set instead of plain text.

For example, in this case you'd return something like this:

Code:
$response = array('name'=>'edgars'); return json_encode($response);

Might take care of that odd whitespace.

If not as a last resort, there are whitespace trim() type functions in javascript that should help.


CI returns invisible symbol string to jquery ajax - El Forum - 01-07-2011

[eluser]Edgars[/eluser]
Neither of that helped. Visually there is no white space when I display it. It's just that length is longer. I think it's not white space like ' ', but it's just '' empty.


CI returns invisible symbol string to jquery ajax - El Forum - 01-07-2011

[eluser]Nick_MyShuitings[/eluser]
in the new CI2.0 branch there is a function that strips invisible characters. That might also be of use... if not I'm officially intrigued Smile


CI returns invisible symbol string to jquery ajax - El Forum - 01-07-2011

[eluser]cideveloper[/eluser]
could this be the problem in your language file?