Javascript API - Javascript Syntax error problem

We are using the Javascript API to set a metadata field.


After setting the API key we have this fairly straight forward bit of code:

    $(document).ready(function(){
    var asset_id='6363';
    var field_id='7527';
    var fvalue='%form_submission_id%';
    setMetadata(asset_id,field_id,fvalue,printResponse);

Whch does what is wanted, but it throws a javascript error:

    Error: syntax error
    Source File: .../_web_services/javascriptapi.js
    Line: 75, Column: 1
    Source Code:
    ()

The error message is actually pointing to the last line here:

    function jsonToObj(json)
    {
    // Make the conversion
    // Don't worry, even the creator of JSON says eval is ok here
    var jsonObj = eval('(' + json + ')');


Using firebug, we've determined that function jsonToOBJ is being passed an empty string,
but I would have thought that this line in function success:
            if (ajaxRequest.responseText !== '' || ajaxRequest.responseText !== 'undefined' || ajaxRequest.responseText !== null) {
                var response = jsonToObj(ajaxRequest.responseText);

Would have prevented function jsonToObj from being called.

Is this a bug?

Can anyone suggest a workaround... please?

regards

Polonius

[quote]
We are using the Javascript API to set a metadata field.



After setting the API key we have this fairly straight forward bit of code:

    $(document).ready(function(){
    var asset_id='6363';
    var field_id='7527';
    var fvalue='%form_submission_id%';
    setMetadata(asset_id,field_id,fvalue,printResponse);

Whch does what is wanted, but it throws a javascript error:

    Error: syntax error
    Source File: .../_web_services/javascriptapi.js
    Line: 75, Column: 1
    Source Code:
    ()

The error message is actually pointing to the last line here:

    function jsonToObj(json)
    {
    // Make the conversion
    // Don't worry, even the creator of JSON says eval is ok here
    var jsonObj = eval('(' + json + ')');


Using firebug, we've determined that function jsonToOBJ is being passed an empty string,
but I would have thought that this line in function success:
            if (ajaxRequest.responseText !== '' || ajaxRequest.responseText !== 'undefined' || ajaxRequest.responseText !== null) {
                var response = jsonToObj(ajaxRequest.responseText);

Would have prevented function jsonToObj from being called.

Is this a bug?

Can anyone suggest a workaround... please?

regards

Polonius
[/quote]


Hi,

The line you pointed out in the success() should actually be AND condition. I will look into it. But what i am wondering is, if the API call is doing what it is doing for you, why is the response returned empty. It should have been a success/failure message.

Also what version of Matrix are you running? prolly that might be helpful for me to see whats going on really.

Cheers,

Ash

We are running 3.28.4

[quote]
We are running 3.28.4

[/quote]





That seems to be a pretty stable version of Matrix. Would be nice to know if there are any errors in the error.log and as mentioned above if the JS API call is achieving what it is designed to do.



Ash.