| We hope you enjoy your visit. You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free. Join our community! If you're already a member please log in to your account to access all of our features: |
| Javascript - Function Isn't Defined; Even though it is? | |
|---|---|
| Tweet Topic Started: Jul 23 2010, 12:00 AM (2,157 Views) | |
| IceMetalPunk | Jul 23 2010, 12:00 AM Post #1 |
|
We are all IMPerfect. Be proud!
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Hey, everyone. I was just testing out Twitter's API and seeing how it works, what queries are needed, etc. I came up with a basic Javascript/AJAX approach, but I can't test it to see if it works because...well, I don't know why. Every time I try to test this, nothing happens. Firefox's error console tells me that PostData, the function I'm using to test the Twitter API, is not defined. It only says this once I try to run it; I'm positive it IS defined. Syntax checkers say the syntax is fine, and I've triple- and quadruple-checked all my function and variable names for typos. Everything seems fine, but still, Firefox thinks PostData is undefined. Here's all the code on the test page:
I click the button, which calls the PostData method. As you can see, PostData is most definitely defined above, so why the heck doesn't Firefox see that? -IMP P.S. I know I don't need the BuildQuery function since it's only one form field, but I like to make my methods as flexible as possible from the beginning. For example, now I can just add new fields in the future and they'll automatically be sent correctly without my needing to mess around with the AJAX. Edited by IceMetalPunk, Jul 23 2010, 12:07 AM.
|
![]() |
|
| Garath531 | Jul 23 2010, 05:27 AM Post #2 |
|
Look, up in the sky! It's a bird! It's a plane! It's Superman!
![]() ![]() ![]() ![]() ![]() ![]()
|
Try changingto
|
![]() |
|
| HolySavior | Jul 23 2010, 05:05 PM Post #3 |
|
if( holy + alcohol){ happycoding()}
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
it could be erroring because when youa re using document.getElementById. you are grabbing that element yes but your not telling it when part of that element. basically you want the value. so i would try
|
![]() |
|
| IceMetalPunk | Jul 23 2010, 05:16 PM Post #4 |
|
We are all IMPerfect. Be proud!
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Yeah, I just figured out both of those problems . I haven't done much Web design lately, so I was reading it as "language='Javascript'" instead of what I really typed, "type='Javascript'". Thanks, though.Though now I'm having another issue with this code. I'm getting security errors for trying to connect to Twitter via AJAX. Since Twitter's API is designed to be used off-site (and therefore I'm fairly certain they allow cross-site scripting), and since their documentation says nothing about any more authorization than a username/password combo like I'm using, can anyone think of a reason I still don't have authorization to connect? I'm positive the username/password combo is correct (it's my personal Twitter account)... -IMP
|
![]() |
|
| HolySavior | Jul 23 2010, 06:30 PM Post #5 |
|
if( holy + alcohol){ happycoding()}
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
hmmm i tried digging alittle deeper. and i dont think you can actually use the API like that. i think if you want to use JS/AJAX you need to use PHP with it. http://www.newwebplatform.com/tips-and-tutorials/Twitter#Javascript/AJAX i found that if that helps alittle bit The API presently supports the following data formats: XML, JSON, and the RSS and Atom syndication formats, with some methods only accepting a subset of these formats. also here are some twitter libraries for JS http://dev.twitter.com/pages/libraries#javascript |
![]() |
|
| Paper | Mar 25 2011, 09:08 PM Post #6 |
|
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
If I'm not mistaken, the cross domain security is implemented by the browser and there's no way of overcoming that without either using a server or a cross-domain scripting attack (which would most likely not work in this case). PHP is the way to go, have a look here: http://www.geekdaily.net/2007/08/31/twitter-javascript-api-the-beginning/ EDIT: Never mind was wrong! Edited by Paper, Mar 25 2011, 09:45 PM.
|
![]() |
|
| 1 user reading this topic (1 Guest and 0 Anonymous) | |
| « Previous Topic · Technology Chat · Next Topic » |
| Track Topic · E-mail Topic |
10:14 AM Jul 11
|



![]](http://b1.ifrm.com/0/1/0/p601690/pipright.png)



Yeah, I just figured out both of those problems
10:14 AM Jul 11