Jquery help

cybershark

Expert Member
Joined
Apr 11, 2006
Messages
1,319
I've got an fckeditor textarea from which I'm getting text to create keywords for the page. I'm having difficulty replacing the commons words in the keywords.

Then I'm wanting to make sure there are no duplicates in the keywords.
And finally to put the keywords in a sortable list, that's submitted as an array with the rest of the form.

Any help would really be appreciated, thanks :)

Code:
  $(document).ready(function(){
       $('#createkwords').bind('click', function() {
       var kwords = $("#pagebody").val();
       var commonWords = new Array("the", "a", "all", "for", "at", "with", "that");
       kwords = kwords.replace(/<\/?[^>]+(>|$)/g,"").replace(/[.:,]/g,"");
       alert(kwords);
       $("#keywords").val(kwords);
       });
});
 

guest2013-1

guest
Joined
Aug 22, 2003
Messages
19,800
Are you trying to generate a keyword list (wordpress terms, tags) for SEO purposes?

I'd suggest www.opencalais.com's tagaroo webservice. I'm currently using it (and a class someone wrote for wordpress) in one of my client's websites and all I do is pass my api key and text I want analyzed to the service, it extracts all the keyword and adds relevant keywords to the topic for me and passes back an array.

If that's not what you're trying to do, then what exactly are you having problems with? "Difficulty" isn't really a description :)

If you'd like, you could just get an API key from the website I suggested and I'll give you access to the webservice already running on www.acidrazor.com seeing as though I amended it to take an API key & text for re-usability by all my other apps...
 

cybershark

Expert Member
Joined
Apr 11, 2006
Messages
1,319
Are you trying to generate a keyword list (wordpress terms, tags) for SEO purposes?

I'd suggest www.opencalais.com's tagaroo webservice. I'm currently using it (and a class someone wrote for wordpress) in one of my client's websites and all I do is pass my api key and text I want analyzed to the service, it extracts all the keyword and adds relevant keywords to the topic for me and passes back an array.
Yes, I'm looking to generate a keyword list, that goes in meta keywords.
Thanks for the url, I've been looking for something like that for wordpress.

If that's not what you're trying to do, then what exactly are you having problems with? "Difficulty" isn't really a description :)
My problem is getting replace to work, right now for example it's matching every "a" in words, instead of just "a" the word.

If you'd like, you could just get an API key from the website I suggested and I'll give you access to the webservice already running on www.acidrazor.com seeing as though I amended it to take an API key & text for re-usability by all my other apps...

Thanks, it would be great if I could get access to it
 

guest2013-1

guest
Joined
Aug 22, 2003
Messages
19,800
Yes, I'm looking to generate a keyword list, that goes in meta keywords.
Thanks for the url, I've been looking for something like that for wordpress.


My problem is getting replace to work, right now for example it's matching every "a" in words, instead of just "a" the word.



Thanks, it would be great if I could get access to it

You wouldn't need anything if you're using wordpress, you can just download and install the tagaroo plugin that does everything for you.

If your keyword list was generated properly you wouldn't need to replace those keywords. Is this an application out of the normal wordpress scope?

www.acidrazor.com/tagger.php

It accepts POST and looks for the parameters "text' and "key" where key is the API key opencalais supplies you and text is the words you'd like to generate the keywords with.

It returns an array of keywords for you if there's enough content, otherwise it just returns "No Tags". All you need is to pass the content of the tinymce editor to the tagger.php including the key and bob's your uncle.

Or, just get the tageroo wordpress plugin :)
 

cybershark

Expert Member
Joined
Apr 11, 2006
Messages
1,319
Yes, my application is out of the scope of wordpress.

Thanks, I'll give the API a try soon.
 

cybershark

Expert Member
Joined
Apr 11, 2006
Messages
1,319
I've got my code working now, but it only works in IE 8, FF returns nothing, and Opera does nothing literally.

I also see in IE 8 5 keywords are being returned.

Code:
  $(document).ready(function(){
	$('#createkwords').click(function() {
	var key = "my key";
        var text = $("#pagebody").val();
	text = text.replace(/<\/?[^>]+(>|$)/g,"");
	
	 $.ajax({
	   type: "POST",
	   url: "http://www.acidrazor.com/tagger.php",
	   data: { key:key, text:text },
	   success: function(msg){
	   alert( "Data Saved: " + msg );
	   $("#keywords").val(msg);
	   }
	});
    });
});
 
Last edited:

guest2013-1

guest
Joined
Aug 22, 2003
Messages
19,800
Not entirely sure why it won't work in FireFox or Opera because the whole point behind jquery is to have a library that all browsers adhere to regardless.

Straight up "msg" won't do as there's an object returned, not clear text. So you need to specify something like msg.responseText...

I tried this in FF now and it works. However, I have my DOCTYPE specified and place the code in the right places... so not entirely sure if yours is bombing because of either of those things.

If FF and Opera returns nothing, it's possible that it's returning some sort of error. So try adding:

Code:
error: function(msg) { alert(msg.responseText) }
onto the ajax statement.
 

guest2013-1

guest
Joined
Aug 22, 2003
Messages
19,800
mmmm? **** that's right. javascript cross domain scripting isn't allowed. I actually call the function from a server side script.

Write a little server side script that will query acidrazor.com and it will in turn relay the keywords to your page. Then in your javascript you just call your own page.
 

cybershark

Expert Member
Joined
Apr 11, 2006
Messages
1,319
I'm still getting undefined problems with success in the ajax :confused:
Edit:
I added dataType: text, now it works, but the alert box still says undefined.

Code:
  	$(document).ready(function(){
		$('#createkwords').click(function() {
			var text = $("#pagebody").val();
			text = text.replace(/<\/?[^>]+(>|$)/g,"")
			alert( "Data Saved: " + text );
			 $.ajax({
			   type: "POST",
			   url: "tagger.php",
			   data: { text:text },
                           dataType: text,
			   success: function(data){
			   alert( "Data Saved: " + data.responseText );
			   $("#keywords").html(data);
			   },
			  error: function(msg) { alert(data.responseText) }
			});
		  });
	});

PHP:
$key = "my key";
$text = $_POST["text"];
$url = "http://www.acidrazor.com/tagger.php";

$curlPost = 'key='  . urlencode($key) . '&text=' . urlencode($text) . '';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
$data = curl_exec($ch);
curl_close($ch);
echo $data;
 
Last edited:
Top