ssossossosso

Forums

Covering OroCRM topics, including community updates and company announcements.  Subscribe

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

  • Creator
    Topic
  • #7516
    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
  • #7517
    Dmitry Khrysev
    Dmitry Khrysev
    Oro Core

    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)

    #7521
    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:

    #7524
    Dmitry Khrysev
    Dmitry Khrysev
    Oro Core

    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.

    #7529
    infocurci
    infocurci
    Participant

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

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

You must be logged in to reply to this topic.