OroPlatform Forums

Covering OroPlatform topics, including community updates and company announcements.

Forums Forums OroPlatform OroPlatform – Programming Questions working with ajax…

This topic contains 4 replies, has 2 voices, and was last updated by infocurci infocurci 5 years, 9 months ago.

Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.

  • Creator
    Topic
  • #33617
    infocurci
    infocurci
    Participant

    Hello,
    I need of execute an Ajax code on my bundle.
    I created my REST function (on Controller/Api/Rest) and it works fine, I tested on app_dev.php/api/doc.
    I tried to call my function on my view, in this mode:

    The function works fine and return this string:

    but on my console I found this error:

    Error: SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data

    There is, on your code, an example to implement correctly an Ajax call?
    Thanks!!!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
    Replies
  • #33618

    Hi.
    Please, avoid usage of real URLs , use URL generation instead.
    X-CSRF-Header is for testing, not for production code.
    We are using require.js for JS modules loading.

    Simple example

    To debug real response you may use Network tab in JS console (Firebug, Chrome Developer Tools)

    #33619
    infocurci
    infocurci
    Participant

    Thanks for your reply.
    Anyway, I have the same problem..
    This is my javascript:

    this is my (little, example purpose) php function:

    this is the result (in my opinion, is right..)

    .. but this is the error:

    #33620

    Note, that getJSON parse data internally.

    The success callback is passed the returned data, which is typically a JavaScript object or array as defined by the JSON structure and parsed using the $.parseJSON() method. It is also passed the text status of the response.

    #33621
    infocurci
    infocurci
    Participant

    Right!!!!
    It works fine now!!!
    Thanks Dmitry!

Viewing 4 replies - 1 through 4 (of 4 total)

The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.

You will be redirected to [title]. Would you like to continue?

Yes No