0

I have jquery ajax call which will go to a .js file and returns JSON

var validate = function () {
    alert('test string');
}

$.ajax({
        url: "JS/JQB/SampleData/Filters.js",
        async:false,
        success: InitailiseJQB
    });

Filters.js file contains below JSON,

  [{
        "id": "Group",
        "filters": [{
            "id": "49be7d78-4dcf-38ab-3733-b4108701f1",            
            "validation": {
                "callback": validate
            }
        }]
}]

in the above JSON validate is the javascript function but the problem is when i am requesting for the JSON using ajax call, it is throwing run time error called JavaScript runtime error: Invalid character

11
  • 2
    That's not valid JSON. The right-hand side of a JSON property clause can be a string, a number, a JSON array, a JSON object, true, false, or null. Commented Aug 6, 2015 at 18:38
  • @Pointy but if i remove the ajax call and put it in a variable then it is replacing the validate with the function I have given, and every thing working fine. Commented Aug 6, 2015 at 18:41
  • You could add the parameter datatype: "JSON" as you are requesting JSON from your script Commented Aug 6, 2015 at 19:08
  • Try your script with some known valid JSON and see if it works. You will find plenty on here. Commented Aug 6, 2015 at 19:17
  • 1
    @user1655222 One option would be to respond with the name (string) of the function -- { "callback": "validate" }. A simple way to reference a function from that name is to store it as a method. Example: jsfiddle.net/xtz9w6k5 Commented Aug 7, 2015 at 2:53

1 Answer 1

0

On success, are you sure you mean to call:

success: InitailiseJQB

There may be an accidental spelling error there.

Sign up to request clarification or add additional context in comments.

1 Comment

as i said it is working fine if i place a string in validate instead of function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.