Welcome Guest, Not a member yet? Register   Sign In
CI returns invisible symbol string to jquery ajax
#1

[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.
#2

[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.
#3

[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.
#4

[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.
#5

[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.
#6

[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
#7

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




Theme © iAndrew 2016 - Forum software by © MyBB