Hi Guys I have created this script to read URLs from a TXT file and the pass them to an array .. this part is working good, but when I try to add the second part of the script that will send each array element to a PHP file to handle it and return the proper results, it doesnt work Before I list the script .. here is the content of Test3.txt http://site.info/ http://site1.info/ http://site.com/ And here is an assumption how the PHP file blogs.php might look: <? $keyword=$_REQUEST[''keyword'']; echo $keyword; ?> Here is my script below, any help is appreciated guys: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <script src="prototype.js"></script> <title>JS</title> </head> <body> <SCRIPT LANGUAGE = JAVASCRIPT> var request = new ActiveXObject(''Msxml2.XMLHTTP''); request.open(''get'', ''Test3.txt'', true); request.onreadystatechange = extractURLs; request.send(); // document.write(responseText); function extractURLs() { // if (request.readyState == 4 && request.status == 200) { urlArray = request.responseText.split("\n") start_your_function(urlArray); // } document.write(urlArray.length); } document.write(urlArray[5] + "<br />"); var i=0 ; var dd= urlArray.length - 1; document.write(dd); document.write(i); for (i=0;i<=dd;i++) { var keyword=urlArray[i]; // When I add this part it is not working any more var request2 = new ActiveXObject(''Msxml2.XMLHTTP''); new Ajax.Request(''blogs.php?=''+keyword, true); Ajax.Responders.register(responder); document.write(i); document.write(keyword + "<br />"); */ } </SCRIPT> </body> </html> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Guys, I am writing this code to pull URLs form txt file and pass them to an array .. (this part is working well) but the second part which is sending each array element to external PHP file to get some results is not working for me. The Text3.txt file is looking like this: http://site.info/ http://site1.info/ http://site.com/ You can assume the blogs.php file will look like this : <? $keyword=$_REQUEST[''keyword'']; echo $keyword; ?> Anybody can help me in that ? your help will be appreciated guys .. here is my code <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <script src="prototype.js"></script> <title>JS</title> </head> <body> <SCRIPT LANGUAGE = JAVASCRIPT> var request = new ActiveXObject(''Msxml2.XMLHTTP''); request.open(''get'', ''Test3.txt'', true); request.onreadystatechange = extractURLs; request.send(); // document.write(responseText); function extractURLs() { // if (request.readyState == 4 && request.status == 200) { urlArray = request.responseText.split("\n") start_your_function(urlArray); // } document.write(urlArray.length); } document.write(urlArray[5] + "<br />"); var i=0 ; var dd= urlArray.length - 1; document.write(dd); document.write(i); for (i=0;i<=dd;i++) { var keyword=urlArray[i]; // When I add this part it is not working any more var request2 = new ActiveXObject(''Msxml2.XMLHTTP''); new Ajax.Request(''blogs.php?=''+keyword, true); Ajax.Responders.register(responder); document.write(i); document.write(keyword + "<br />"); */ } </SCRIPT> </body> </html> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Why are you making XHRs w/ the proprietary activeX syntax? There is your first problem, adopt Ajax.Request for any and all XHRs and half your problems will be solved. Also be careful when sending an array of data. When you have identically named pairs you can lose data. You''ve got to use the square bracket notation on your names, check out this demo i set up. The responder justs print_r() the $_POST array.. http://positionabsolute.net/projects/javascript/name-pair-test.html Lose data var str = "name=matt&name=william&name=tobie&name=sam"; preserve data var str = "name[]=matt&name[]=william&name[]=tobie&name[]=sam"; On Nov 14, 4:21 pm, TheWis <wi...-Vvc3hXHcc0g0E5HM+x08VNkmqwFzkYv6@public.gmane.org> wrote:> Hi Guys, I am writing this code to pull URLs form txt file and pass > them to an array .. (this part is working well) but the second part > which is sending each array element to external PHP file to get some > results is not working for me. > > The Text3.txt file is looking like this: > > http://site.info/http://site1.info/http://site.com/ > > You can assume the blogs.php file will look like this : > > <? > $keyword=$_REQUEST[''keyword'']; > echo $keyword; > ?> > > Anybody can help me in that ? your help will be appreciated guys .. > here is my code > > <html> > <head> > <meta http-equiv="Content-Type" content="text/html; > charset=windows-1252"> > <script src="prototype.js"></script> > <title>JS</title> > </head> > <body> > <SCRIPT LANGUAGE = JAVASCRIPT> > var request = new ActiveXObject(''Msxml2.XMLHTTP''); > request.open(''get'', ''Test3.txt'', true); > request.onreadystatechange = extractURLs; > request.send(); > // document.write(responseText); > function extractURLs() { > // if (request.readyState == 4 && request.status == 200) { > urlArray = request.responseText.split("\n") > start_your_function(urlArray); > // } > document.write(urlArray.length); > > } > document.write(urlArray[5] + "<br />"); > var i=0 ; > var dd= urlArray.length - 1; > > document.write(dd); > document.write(i); > for (i=0;i<=dd;i++) > { > var keyword=urlArray[i]; > // When I add this part it is not working any more > var request2 = new ActiveXObject(''Msxml2.XMLHTTP''); > > new Ajax.Request(''blogs.php?=''+keyword, true); > > Ajax.Responders.register(responder); > > document.write(i); > > document.write(keyword + "<br />"); */ > > } > > </SCRIPT> > > </body> > > </html>--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Richard Quadling
2007-Nov-16 10:07 UTC
Re: Protype and communicating with external PHP file
On 15/11/2007, Matt Foster <mattfoster01-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Why are you making XHRs w/ the proprietary activeX syntax? There is > your first problem, adopt Ajax.Request for any and all XHRs and half > your problems will be solved. > > Also be careful when sending an array of data. When you have > identically named pairs you can lose data. You''ve got to use the > square bracket notation on your names, check out this demo i set up. > The responder justs print_r() the $_POST array.. > > http://positionabsolute.net/projects/javascript/name-pair-test.html > > > Lose data > var str = "name=matt&name=william&name=tobie&name=sam"; > > preserve data > var str = "name[]=matt&name[]=william&name[]=tobie&name[]=sam";There is a potential workaround. Try this as your php script ... <?php phpinfo(); ?> Now run that like this ... http://www.your-site.com/phpinfo.php?test=1&test=2 If you look through the config of your server, looking for test, you will see that ... $_SERVER[''QUERY_STRING''] = ''test=1&test=2'' $_SERVER[''REQUEST_URI''] = ''/phpinfo.php?test=1&test=2'' But, as correctly mentioned by Matt, both $_GET and $_REQUEST (and $_POST if that was the submission method) will lose the data. I don''t have a script to convert QUERY_STRING into an array that is 100% perfect (I''ve just realised that you can have multiple levels of keys to support which makes it a little more awkward. But, assuming the reason that you are using QUERY_STRING is because you have not supplied keys (or used [] at all), then the following script will help ... <?php // This function takes the servers QueryString and converts it to an array. // It will deal with repeated names. // An array is returned. // NOTE: This function is specifically ignoring keys - if you have supplied keys, then // you would not normally require this function. function queryStringToArray() { // Default result is empty array. $a_Result = array(); // Do we have anything to convert? if ('''' != $_SERVER[''QUERY_STRING'']) { // Split the query string on a real &. $a_Parts = preg_split(''`&(?!amp;)`sim'', $_SERVER[''QUERY_STRING'']); // Process each part into the result array. foreach($a_Parts as $s_Part) { $i_EqualPos = strpos($s_Part, ''=''); // If no = or = is at the end of Part, then Part is Name and Value is empty string. if ((0 == $i_EqualPos) || (strlen($s_Part) == 1 + $i_EqualPos)) { // Remove any trailing $s_Name = rtrim($s_Part, ''=''); $s_Value = ''''; } else { // Split on the first $s_Name = substr($s_Part, 0, $i_EqualPos); $s_Value = substr($s_Part, 1 + $i_EqualPos); } // Does Name exist? if (array_key_exists($s_Name, $a_Result)) { // Make the stored value an array and add the new value. $a_Result[$s_Name] = array($a_Result[$s_Name], $s_Value); } else { // Add the name/value to the results array. $a_Result[$s_Name] = $s_Value; } } } return $a_Result; } ?> Usage would be ... <?php $a_Data = queryStringToArray(); ?> As an example, test.php?test=1&test=2&test=3 results in an array of ... array ( ''test'' => array ( 0 => array ( 0 => ''1'', 1 => ''2'', ), 1 => ''3'', ), ) Richard.> On Nov 14, 4:21 pm, TheWis <wi...-Vvc3hXHcc0g0E5HM+x08VNkmqwFzkYv6@public.gmane.org> wrote: > > Hi Guys, I am writing this code to pull URLs form txt file and pass > > them to an array .. (this part is working well) but the second part > > which is sending each array element to external PHP file to get some > > results is not working for me. > > > > The Text3.txt file is looking like this: > > > > http://site.info/http://site1.info/http://site.com/ > > > > You can assume the blogs.php file will look like this : > > > > <? > > $keyword=$_REQUEST[''keyword'']; > > echo $keyword; > > ?> > > > > Anybody can help me in that ? your help will be appreciated guys .. > > here is my code > > > > <html> > > <head> > > <meta http-equiv="Content-Type" content="text/html; > > charset=windows-1252"> > > <script src="prototype.js"></script> > > <title>JS</title> > > </head> > > <body> > > <SCRIPT LANGUAGE = JAVASCRIPT> > > var request = new ActiveXObject(''Msxml2.XMLHTTP''); > > request.open(''get'', ''Test3.txt'', true); > > request.onreadystatechange = extractURLs; > > request.send(); > > // document.write(responseText); > > function extractURLs() { > > // if (request.readyState == 4 && request.status == 200) { > > urlArray = request.responseText.split("\n") > > start_your_function(urlArray); > > // } > > document.write(urlArray.length); > > > > } > > document.write(urlArray[5] + "<br />"); > > var i=0 ; > > var dd= urlArray.length - 1; > > > > document.write(dd); > > document.write(i); > > for (i=0;i<=dd;i++) > > { > > var keyword=urlArray[i]; > > // When I add this part it is not working any more > > var request2 = new ActiveXObject(''Msxml2.XMLHTTP''); > > > > new Ajax.Request(''blogs.php?=''+keyword, true); > > > > Ajax.Responders.register(responder); > > > > document.write(i); > > > > document.write(keyword + "<br />"); */ > > > > } > > > > </SCRIPT> > > > > </body> > > > > </html> > > >-- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Richard Quadling
2007-Nov-16 10:11 UTC
Re: Protype and communicating with external PHP file
Oops. Sorry. <?php // This function takes the servers QueryString and converts it to an array. // It will deal with repeated names. // An array is returned. // NOTE: This function is specifically ignoring keys - if you have supplied keys, then // you would not normally require this function. function queryStringToArray() { // Default result is empty array. $a_Result = array(); // Do we have anything to convert? if ('''' != $_SERVER[''QUERY_STRING'']) { // Split the query string on a real &. $a_Parts = preg_split(''`&(?!amp;)`sim'', $_SERVER[''QUERY_STRING'']); // Process each part into the result array. foreach($a_Parts as $s_Part) { $i_EqualPos = strpos($s_Part, ''=''); // If no = or = is at the end of Part, then Part is Name and Value is empty string. if ((0 == $i_EqualPos) || (strlen($s_Part) == 1 + $i_EqualPos)) { // Remove any trailing $s_Name = rtrim($s_Part, ''=''); $s_Value = ''''; } else { // Split on the first $s_Name = substr($s_Part, 0, $i_EqualPos); $s_Value = substr($s_Part, 1 + $i_EqualPos); } // Does Name exist and is it not an array if (array_key_exists($s_Name, $a_Result)) { if (!is_array($a_Result[$s_Name])) { // Make the stored value an array. $a_Result[$s_Name] = array($a_Result[$s_Name]); } // Add the value to the name array $a_Result[$s_Name][] = $s_Value; } else { // Add the name/value to the results array. $a_Result[$s_Name] = $s_Value; } } } return $a_Result; } ?> On 16/11/2007, Richard Quadling <rquadling-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 15/11/2007, Matt Foster <mattfoster01-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Why are you making XHRs w/ the proprietary activeX syntax? There is > > your first problem, adopt Ajax.Request for any and all XHRs and half > > your problems will be solved. > > > > Also be careful when sending an array of data. When you have > > identically named pairs you can lose data. You''ve got to use the > > square bracket notation on your names, check out this demo i set up. > > The responder justs print_r() the $_POST array.. > > > > http://positionabsolute.net/projects/javascript/name-pair-test.html > > > > > > Lose data > > var str = "name=matt&name=william&name=tobie&name=sam"; > > > > preserve data > > var str = "name[]=matt&name[]=william&name[]=tobie&name[]=sam"; > > There is a potential workaround. > > Try this as your php script ... > > <?php phpinfo(); ?> > > Now run that like this ... > > http://www.your-site.com/phpinfo.php?test=1&test=2 > > If you look through the config of your server, looking for test, you > will see that ... > > $_SERVER[''QUERY_STRING''] = ''test=1&test=2'' > $_SERVER[''REQUEST_URI''] = ''/phpinfo.php?test=1&test=2'' > > But, as correctly mentioned by Matt, both $_GET and $_REQUEST (and > $_POST if that was the submission method) will lose the data. > > I don''t have a script to convert QUERY_STRING into an array that is > 100% perfect (I''ve just realised that you can have multiple levels of > keys to support which makes it a little more awkward. > > But, assuming the reason that you are using QUERY_STRING is because > you have not supplied keys (or used [] at all), then the following > script will help ... > > <?php > // This function takes the servers QueryString and converts it to an array. > // It will deal with repeated names. > // An array is returned. > // NOTE: This function is specifically ignoring keys - if you have > supplied keys, then > // you would not normally require this function. > function queryStringToArray() > { > // Default result is empty array. > $a_Result = array(); > > // Do we have anything to convert? > if ('''' != $_SERVER[''QUERY_STRING'']) > { > // Split the query string on a real &. > $a_Parts = preg_split(''`&(?!amp;)`sim'', $_SERVER[''QUERY_STRING'']); > > // Process each part into the result array. > foreach($a_Parts as $s_Part) > { > $i_EqualPos = strpos($s_Part, ''=''); > // If no = or = is at the end of Part, then Part is Name and Value > is empty string. > if ((0 == $i_EqualPos) || (strlen($s_Part) == 1 + $i_EqualPos)) > { > // Remove any trailing > $s_Name = rtrim($s_Part, ''=''); > $s_Value = ''''; > } > else > { > // Split on the first > $s_Name = substr($s_Part, 0, $i_EqualPos); > $s_Value = substr($s_Part, 1 + $i_EqualPos); > } > > // Does Name exist? > if (array_key_exists($s_Name, $a_Result)) > { > // Make the stored value an array and add the new value. > $a_Result[$s_Name] = array($a_Result[$s_Name], $s_Value); > } > else > { > // Add the name/value to the results array. > $a_Result[$s_Name] = $s_Value; > } > } > } > > return $a_Result; > } > ?> > > Usage would be ... > > <?php > $a_Data = queryStringToArray(); > ?> > > As an example, test.php?test=1&test=2&test=3 > > results in an array of ... > > array ( ''test'' => array ( 0 => array ( 0 => ''1'', 1 => ''2'', ), 1 => ''3'', ), ) > > Richard. > > > On Nov 14, 4:21 pm, TheWis <wi...-Vvc3hXHcc0g0E5HM+x08VNkmqwFzkYv6@public.gmane.org> wrote: > > > Hi Guys, I am writing this code to pull URLs form txt file and pass > > > them to an array .. (this part is working well) but the second part > > > which is sending each array element to external PHP file to get some > > > results is not working for me. > > > > > > The Text3.txt file is looking like this: > > > > > > http://site.info/http://site1.info/http://site.com/ > > > > > > You can assume the blogs.php file will look like this : > > > > > > <? > > > $keyword=$_REQUEST[''keyword'']; > > > echo $keyword; > > > ?> > > > > > > Anybody can help me in that ? your help will be appreciated guys .. > > > here is my code > > > > > > <html> > > > <head> > > > <meta http-equiv="Content-Type" content="text/html; > > > charset=windows-1252"> > > > <script src="prototype.js"></script> > > > <title>JS</title> > > > </head> > > > <body> > > > <SCRIPT LANGUAGE = JAVASCRIPT> > > > var request = new ActiveXObject(''Msxml2.XMLHTTP''); > > > request.open(''get'', ''Test3.txt'', true); > > > request.onreadystatechange = extractURLs; > > > request.send(); > > > // document.write(responseText); > > > function extractURLs() { > > > // if (request.readyState == 4 && request.status == 200) { > > > urlArray = request.responseText.split("\n") > > > start_your_function(urlArray); > > > // } > > > document.write(urlArray.length); > > > > > > } > > > document.write(urlArray[5] + "<br />"); > > > var i=0 ; > > > var dd= urlArray.length - 1; > > > > > > document.write(dd); > > > document.write(i); > > > for (i=0;i<=dd;i++) > > > { > > > var keyword=urlArray[i]; > > > // When I add this part it is not working any more > > > var request2 = new ActiveXObject(''Msxml2.XMLHTTP''); > > > > > > new Ajax.Request(''blogs.php?=''+keyword, true); > > > > > > Ajax.Responders.register(responder); > > > > > > document.write(i); > > > > > > document.write(keyword + "<br />"); */ > > > > > > } > > > > > > </SCRIPT> > > > > > > </body> > > > > > > </html> > > > > > > > > > -- > ----- > Richard Quadling > Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 > "Standing on the shoulders of some very clever giants!" >-- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---