You're using jQuery to make the JSON call, but the rest of your syntax is
classic javascript. Try using jQuery for the whole statement and you can
probably skip all of the looping. Something like this might work:
$.getJSON("ispeerreviewed.php?issn=" + issn
+"&jsoncallback=?",function(json, textStatus) {
var issnSnippet = "(" + issn +") Peer Reviewed: " + json.peerreviewed;
$(".theClass").html(issnSnippet);
});
Jquery selectors[1] are really powerful (and strangely satisfying), and tend
to make life a lot simpler.
http://docs.jquery.com/Selectors
-Andy
On 11/5/09 7:45 AM, "Michael Beccaria" <[log in to unmask]> wrote:
> Demian,
> I tried calling the functions following the browser domready event and the
> browser load event. Same results. I'm actually just thinking about making a
> link that says "More Information about this title" and have it link to another
> page that gives the metadata from xissn. Seems like it's a bit easier and
> almost as effective...unless there is a solution I don't know about yet:)
> Mike
>
>
> ________________________________
>
> From: Code for Libraries on behalf of Demian Katz
> Sent: Thu 11/5/2009 7:02 AM
> To: [log in to unmask]
> Subject: Re: [CODE4LIB] Jquery jsonp question
>
>
>
> In what context is the code running? I haven't used jquery, so I can't give
> exact syntax, but other similar libraries have ways of attaching functions to
> events like "load" or "domready." If your theory about the code running too
> quickly is correct, it might just be a matter of deferring execution until the
> document is loaded and ready to be manipulated.
>
> Also, a general tip -- if you haven't already, you might find it worthwhile to
> test your code in a variety of different browsers. With weird timing bugs,
> you'll sometimes see distinctly different failures in different browsers and
> get different types of feedback. It's often helpful to compare these varying
> results in order to track down the cause.
>
> - Demian
> ________________________________________
> From: Code for Libraries [[log in to unmask]] On Behalf Of Michael
> Beccaria [[log in to unmask]]
> Sent: Wednesday, November 04, 2009 9:18 PM
> To: [log in to unmask]
> Subject: [CODE4LIB] Jquery jsonp question
>
> Hey all,
> I'm having some problems with some ajaxy stuff and was hoping someone
> can point me in the right direction.
>
> The project is as follows:
> I'm trying to take this page
> (http://lg8eg4nk4x.search.serialssolutions.com/?S=T_W_A&V=1.0&N=100&L=LG
> 8EG4NK4X&C=test) and grab the issn and query my server which returns
> whether the issn is peer reviewed or not.
>
> I'm using jquery. Here is the piece of my js code that cycles through
> the issn numbers:
> if (allHTMLTags[i].className==theClass) {
> var originalTag = allHTMLTags[i].innerHTML;
> var issn =
> originalTag.replace("(","").replace(")","");
> alert('test');
>
> $.getJSON("http://library.paulsmiths.edu/issnsearch/ispeerreviewed.php?i
> ssn=" + issn + "&jsoncallback=?",function(json, textStatus) {
> alert("test2");
> allHTMLTags[i].innerHTML= "(" + issn +
> ") Peer Reviewed: " + json.peerreviewed;
> });
> }
> }
> }
>
> The problem is if I remove the "alert" items that print out "test and
> "test2", the program cycles indefinitely, hits my server a million
> times, and freezes my browser. With the alerts, it works as expected. I
> suspect the script is running too fast and is unable to get a response
> from the $.getJSON query in time before it hits the innerHTML command.
> How is this usually handled in ajax stuff? I'm new to it all.
> Thanks,
>
> Mike Beccaria
> Systems Librarian
> Head of Digital Initiatives
> Paul Smith's College
> 518.327.6376
|