coderfin / byutv-jsonp

The byutv-jsonp element (<byutv-jsonp>) exposes network request functionality. It is a Polymer v1.0+ element that facilitates making JSONP requests. It uses Polymer behaviors (Byutv.behaviors.Jsonp). It is patterned after Polymer's iron-ajax element (<iron-ajax>). It has been tested using unit tests. It is part of the BYUtv Elements group of elements.

Home Page:http://coderfin.github.io/byutv-jsonp/components/byutv-jsonp/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to solve Uncaught SyntaxError: Unexpected token : ?

rajasimon opened this issue · comments

<byutv-jsonp
  auto
  url="https://ajax.googleapis.com/ajax/services/search/news?v=1.0&rsz=8&pz=1&cf=all&ned=in&hl=en&topic=tc"
  debounce-duration="300"
  callbackKey = "callback"
  last-response="{{lastResponse}}"
  last-error="{{lastError}}"></byutv-jsonp>

This looks like very simple right? but it throws below error

Uncaught SyntaxError: Unexpected token :

How to solve this ?

I am having the exact same problem

Currently the query parameters that are added to the end of the url attribute need to be removed from the url attribute and added to the params attribute as a double quoted JSON string.

For example:

<byutv-jsonp
    auto
    url="https://ajax.googleapis.com/ajax/services/search/news"
    params='{"v":"1.0","rsz":"8","pz":"1","cf":"all","ned":"in","hl":"en","topic":"tc"}'
    last-response="{{lastResponse}}"
    last-error="{{lastError}}"
    debounce-duration="300"></byutv-jsonp>

I have tested this and it should resolve your problem. Does this change work for you?

Also, the default callback-key is callback; there is no need to add this attribute in your case. If you do need to customize the callback key the attribute should be written as callback-key not callbackKey

This issue was resolved here and on this stackoverflow question. There could possibly be an enhancement made to output a more helpful error message or allow query parameters in the URL attribute. If these enhancements are desired please open a new issue.

@coderfin what if i want to send some variable in my params? In this case the params are static but i need the case where the params are dynamic.

@gauravkk22 Can you try something like this: https://stackoverflow.com/a/34165439/2344083