0

Hi,

I have this bit of php returning the response, just for testing :

header('Content-type: application/json');

$response = array();
$response["status"] = "ok";

echo json_encode( $response );

1) Is this a wrong way to send a json encoded string back via jquery ajax?

2) I get NOTHING, No response from this ajax call made by jquery - Even no errors alerted..

$.ajax({
    url: 'controllers/update_page_positions.php',
    data: {id: id, placering: placering},       
    type: 'GET',
    dataType: 'json',

    succes: function( data ) {
        if( data.status == "ok" ) {
            alert('ajax ok..'); 
        }
        else {
            alert('ajax fejl..');       
        }
    },
    error: function (xhr, ajaxOptions, thrownError) {
            alert(xhr.status);
            alert(thrownError);
            alert( xhr.responseText);
    }
});

What am I doing wrong here?

**EDIT: See attached img from Firebug - I get status 200 returned in the console, and I can see the response as the image shows...

So am I handling the response in a wrong way - Or is it the php string I am formatting incorrect?**

Best, Klemme

Edited by klemme

Attachments FireShot_Screen_Capture_#003_-_Content_Manager_-_Dashboard_-_localhost_responsive_grid_layout_backend_dashboard_php.png 5.02 KB img2.png 5.13 KB
2
Contributors
2
Replies
23
Views
4 Years
Discussion Span
Last Post by klemme
1

I don't think you need the header.
The json_encode is fine I think.

succes: function( data ) {

Should be

success: function( data ) {

Edited by diafol

0

Aaahhh, Haha - Thanks for pointing that out diafol..... (solved..)

/Klemme

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.