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

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

Recommended Answers

All 2 Replies

Member Avatar

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

succes: function( data ) {

Should be

success: function( data ) {

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


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.