EllisLab text mark
Advanced Search
     
CI returns invisible symbol string to jquery ajax
Posted: 05 January 2011 06:24 PM   [ Ignore ]
Joined: 2010-11-15
9 posts

Don’t know if It’s Jquery or CI, but I have a situation.
I have simple controller with function

function eds (){    
           
echo "edgars";
           

And I have html file with javascript and Jquery ajax in it.

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.

 
Posted: 06 January 2011 12:58 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2010-08-22
264 posts

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.

 
Posted: 06 January 2011 05:23 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2010-11-15
9 posts

When I remove

$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

$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.

 
Posted: 06 January 2011 12:09 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2010-08-22
264 posts

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:

$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.

 
Posted: 07 January 2011 12:58 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Joined: 2010-11-15
9 posts

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.

 
Posted: 07 January 2011 01:01 PM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2010-08-22
264 posts

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

 
Posted: 07 January 2011 04:58 PM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-06
317 posts

could this be the problem in your language file?