tags:

views:

90

answers:

2
+1  A: 

If you're using using JSONP, then the response should be some kind of Javascript. The problem seems to be that it's trying to run eval on XML which is not valid Javascript (from what I can see after I accessed the link you provided). This is why you're seeing the parser error. It seems like QuickBase isn't generating valid Javascript.

If you have access to something on the server-side, you can create a proxy that goes to QuickBase and returns XML to your AJAX call. This is probably your best bet (especially if QuickBase doesn't support JSONP).

The way JSONP defeats the same-origin policy is by using a SCRIPT. The SCRIPT tag doesn't conform to the same-origin policy and therefore you can load Javascript files that are on a different domain. To use JSONP however, the host site must be JSONP-aware. This means that if you specify a callback in a request, it must return valid Javascript that uses the callback you specified in your request. So if QuickBase was JSONP-aware, it might return something like this:

jsonp1284044371978({
   qdbapi: {
      action: "API AddRecord",
      errcode: 32,
      errtext: "No such database",
      errdetail: "The application does not exist or was deleted. If you followed a link to get here, you may want to inform the author of that link that the application no longer exists.",
      dbid: "xxxxxx"
   }
});

This data is now in a SCRIPT tag which gets immediately evaluated. Since you specified a callback function, your callback will now be called with the data returned by QuickBase.

The problem you're facing is that the data returned by QuickBook is XML and not Javascript. So your SCRIPT tag looks like this:

<script type="text/javascript" src="https://www.quickbase.com/db/xxxxxx?act=API_AddRecord&amp;apptoken=xxxxxxxx&amp;callback=jsonp1284044371978&amp;_fid_11=www.domain.com&amp;_fid_12=xxxxx&amp;_fid_17=xxxxxx&amp;_fid_6=xxxxx&amp;_fid_10=xxxxxxxx&amp;=No+Thanks"&gt;
</script>

Which is essentially:

<script type="text/javascript">
<qdbapi>
   <action>API_AddRecord</action>
   <errcode>32</errcode>
   <errtext>No such database</errtext>
   <errdetail>
      The application does not exist or was deleted. If you followed a link to get here, you may want to inform the author of that link that the application no longer exists. 
   </errdetail>
   <dbid>xxxxxx</dbid>
</qdbapi>
</script>

And this, as you know is not valid Javascript. Unfortunately, in this situation, there is no way to get around this problem without using a proxy (as far as I know, you cannot "intercept" the data that the SCRIPT tag receives). Regardless of how the data is being returned, you can wrap it in an alternate form with a proxy or even return it as straight XML (jQuery supports that). If you have a proxy, instead of calling QuickBase, you will call your proxy, which in turn calls QuickBase. Your proxy then returns the XML to your AJAX call. The only change you really need it to set dataType in the jQuery AJAX call to xml instead of jsonp.

EDIT

Per Jon's comment, you can use an IFRAME as well.

Vivin Paliath
Vivan, you're correct and I had considered that. However, because Quickbase's API doesn't have an option to return the response in an alternate form, I was hoping to change the returned data to something that the JS parser wouldn't throw an error on: something like "var something = null".Can you think of a reason that I can't intercept the data before it gets parsed?
jon_brockman
@jon_brockman I'll edit my answer because it'll take a bit too long to explain it here.
Vivin Paliath
Thanks Vivian, you were right. What I was trying to do wasn't going to work so I did it with an iframe instead.
jon_brockman
@jon_brockman forgot about the iframe -- that works too.
Vivin Paliath
A: 

This might help - https://quickbase-script-engine.heroku.com/ - it can return JSON

gareth