Welcome Guest, Not a member yet? Register   Sign In
Handling returned JSON data
#11

[eluser]dettie[/eluser]
I havent, how does that go?
#12

[eluser]CroNiX[/eluser]
Code:
header('Content-type: application/json');
echo json_encode($array);
#13

[eluser]dettie[/eluser]
It tries to return a plain text-file download when I use that.

I'm using this Javascript btw: https://github.com/johnlanz/jquery-fileu...odeigniter
#14

[eluser]Jason Stanley[/eluser]
Have you done the following to see what you actually have?

Code:
console.log(data);

You can then view in Firebug or webkit web inspector what data actually contains.

You may also want to investigate this function: http://api.jquery.com/jQuery.parseJSON/
#15

[eluser]Aken[/eluser]
Yeah, your Javascript is probably interpreting the JSON string is a normal text string, and not as a JSON object.
#16

[eluser]pictwist[/eluser]
Hello,
Try to use
Code:
var d = jQuery.parseJSON(data);
$("#content").append(d.file_name);
#17

[eluser]CroNiX[/eluser]
Whatever plugin you are using uses jquery ajax. Try setting the dataType: 'json', to tell it the expected returned result will be json.

I use ajax/json all of the time with CI, so I know it works once it is set up properly.
#18

[eluser]dettie[/eluser]
Thanks everyone for the replies/help I really appreciate it--
I don't believe the Jquery upload script used supports JSON return at all, check out the options: http://pixelcone.com/fileuploader/documentation/
I don't see a datatype or anything similar.

I tried using jQuery.parseJSON(data); but that also does not seem to work..
I suppose I can try using another upload/ajax method if this one doesn't work out (any recommendations?)
#19

[eluser]CroNiX[/eluser]
Try manually setting the global ajax config.
Code:
$.ajaxSetup({
  dataType: 'json'
});
Sorry, running out of ideas for you.
#20

[eluser]oursteps[/eluser]
I have the same problem as dettie.

Code:
$.ajax({
  type: 'POST',
  url: "<?php echo site_url('site/submit'); ?>",
  data: form_data,
  datatype: 'json',
  success: function(data) {
   alert(data.url);
  }
});

it returns "undefined".

if I change
Code:
alert(data.url)
to
Code:
alert(data)
, it displays the right output:
Code:
{"ajax":"1","url":"web url"}

bug?

the same on safari and firefox on Mac.




Theme © iAndrew 2016 - Forum software by © MyBB