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&apptoken=xxxxxxxx&callback=jsonp1284044371978&_fid_11=www.domain.com&_fid_12=xxxxx&_fid_17=xxxxxx&_fid_6=xxxxx&_fid_10=xxxxxxxx&=No+Thanks">
</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.