Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Jquery ajax return headers

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #41559
    fooman
    Participant

    I have always used the “evil” eval() function in javascript to process my returning data from an ajax request.


    $.ajax({
    type: "POST",
    url: "includes/get-content.php",
    data: { 'input': $("#input").val() },
    succes: function(data){
    data = eval("("+data+")");
    $("#return-data").html(data);
    },
    error: function(jqXHR, textStatus, errorThrown){
    $("#return-data").html("Error: "+errorThrown);
    }
    });

    I have always read that using eval() bad form. I’m not sure if this is still true today as a lot of the argument was for it being slow a few years back.

    Anyways, using the example above, how would I change things up to passback json? If I set the dataType parameter to ‘json’, I still get a html/text string returned. I am probably missing something very newb and obvious.

Viewing 1 post (of 1 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.