jQuery AJAX can't work with JSON response

Quhalix89

I have a JSON response from my php file like:

[
  {"id":"1"},
  {"archiveitem":"<small>26.06.2015 12:25<\/small><br \/><span class=\"label label-default\">Bug<\/span> has been submitted by Admin"}
]

And try to fetch this response into a div after button was clicked, however firebug is telling me the message from the error-handler. I can't figure out the problem?

$('#loadarchive').click(function(){
    $.ajax({
        type: 'post',
        url: '/src/php/LoadAdminDashboardArchive.php',
        dataType: 'json',
        data: {
            action : 'getArchive'
        },
        success: function(results) {
            var archiveelements = JSON.parse(results);
            console.log(results);
            $.each(archiveelements, function(){
                $('#archivecontent').html('<div class="mark-read-container"><span class="btn-mark-unread" id="' + this.id + '">Unarchive</span></div><div class="bs-callout bs-callout-default">' + this.archiveitem + '</div>');
            });
        },
        error: function(){
            console.log('Cannot retrieve data.');
        }
    });
});
Quhalix89

I was able to get it working and the problem was quite simple...

I forgot to paste the "button" - source code that initiated the ajax request. It was an Input of type "submit" and therefore the page reloaded by default after the response was retrieved successfully... so e.preventDefault(); was the way to go.

Thanks to all of you.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

JQuery Ajax Json Response Does not Work

From Dev

Can't get ajax request to work in jquery with json

From Dev

Jquery - Can't remove() from AJAx response

From Dev

jquery can't alert ajax response

From Dev

Can't get jQuery ajax method to work

From Dev

Javascript/JQuery AJAX can't parse AJAX response

From Dev

Jquery Chosen Select plugin doesn't Work in PHP Ajax response

From Dev

Why can't I parse a Ajax html GET response in jQuery?

From Dev

Can't get response after click on a link using jquery/ajax

From Dev

Can't create table in HTML using AJAX and JSON response

From Dev

handle json response in jquery ajax

From Dev

Use Jquery ajax json response?

From Dev

Jquery/Ajax - Parse JSON Response

From Dev

Can't get Ajax response

From Dev

Can't get basic AJAX script to work, new to jQuery and Javascript

From Dev

Jquery ajax with JSON return can't access to data inside the JSON

From Dev

I can't get this ajax call to work, no json output

From Dev

response to ajax with file doesn't work

From Dev

Wordpress AJAX doesn't work - response 0

From Dev

Can't get json data from jQuery ajax call

From Dev

Controller can't receive JSON from JQuery.ajax

From Dev

how can I parse ajax response in jquery?

From Dev

Can I use jquery ajax response for Autocomplete

From Dev

how to print json array in jquery with ajax response

From Dev

jQuery looping through ajax json response

From Dev

Mapping JSON AJax response to JQuery auto complete

From Dev

Jquery ajax populate dropdown with json response data

From Dev

jQuery Ajax Json response - check if is null

From Dev

Jquery ajax populate dropdown with json response data

Related Related

HotTag

Archive