campaignzero/campaign-zero-widget

submission button broken with embedded script on other sites

bphaigh opened this issue · 7 comments

using this code:

<script async src="https://embed.joincampaignzero.org/widget.js" charset="utf-8"></script>

on a site, entering zip code and hitting submit results in a 404. Looking at the console, it appears that the script is attempting to access app/legislators.php on the server hosting the page (vs the widget).

I haven't had time to test this out myself (and if someone doesn't get to this first I might be able to submit a fix when I have a moment), but I suspect app.js line 102 where jsonpUrl is initialized - the ./app path is making it try to load off the server hosting the the script tag.

I've tried fiddling with this a little on a couple of my own servers but am running into cross-browser security issues with the JSON. Ran out of time for now so I thought I'd post here.

In the meantime I put up a test link that shows this issue in action:

http://longgoneblond.com/widget-test.php

I am having the same issue. When i submit the script is trying to run the file on my server instead of reaching out to the proper one (see attached)

error

Might have a fix for this -- my test widget link is working now (apart from the googlemap part since I don't have a key). Going to do a little more testing/documenting fixes and submit.

@bphaigh I am not 100% sure what you are trying to do with this issue being reported. If you are trying to run the widget on your website, you simply need to follow the instructions in the repos README.md file.

The way you are using the widget right now is basically you copying the entire project onto a different server and running everything there. This is not needed at all if you are just wanting to use our widget on your site.

This is the exact reason you are getting the errors you have posted, because your http://longgoneblond.com/widget-test.php page is loading the our widget on YOUR server, not ours.

e.g. your code looks like this:

<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>Welcome to Long Gone Blond.</title>
</head>
<body>
    <h2>Updated Campaign Zero widget.</h2>
    <p>Updated widget is embedded here:</p>
    <p>My widget is hosted on another personal server to replicate the cross-domain eperience.</p>
    <script async src="http://occupylofi.com/js/campaign-zero-widget/widget.js" charset="utf-8"></script>
</body>

When it should look like this:

<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>Welcome to Long Gone Blond.</title>
</head>
<body>
    <h2>Updated Campaign Zero widget.</h2>
    <p>Updated widget is embedded here:</p>
    <p>My widget is hosted on another personal server to replicate the cross-domain eperience.</p>
    <script async src="https://embed.joincampaignzero.org/widget.js" charset="utf-8"></script>
</body>

If you do in fact intend to duplicate our production server on your own server, you will need to sort out your own server issues as that is not something we can really help with.

However, if you are just trying to get a copy of our widget running on your own website, you can just use the embed examples posted in our README.md file.

That test link actually is running my fixed code now - I'm cleaning it up and will be submitting it shortly.. I came across two issues that were keeping a couple of rest service calls from working when the script is called from a third party site.

If its something in our code that was causing issues, definitely submit a Pull Request for us to take a look at :) Just make sure to read the CONTRIBUTING.md file for what we would need to a Pull Request. You should automatically get these instructions when making a PR. Pushing code directly into the master branch is disabled without submitting a PR for review.

just did the pull request -- the only caveat is, I'm pretty new to git (we use svn here) -- pretty sure it's all packaged up as needed but if anything seems off let me know.

This has been resolved for a while now, but forgot to close out this issue. This has been fixed since v1.0.13.