November 29, 201114 yr I'm starting on a plugin for SNAP and I've noticed that PHP is there (totally awesome). But I'd like to use jquery for grid display. And is there ajax support as well?
November 30, 201114 yr Can't answer your question but cool that you are going to create a plugin, I already use your SNAP setup without unMenu.
November 30, 201114 yr Don't think jquery is included unless one uses the simple features GUI plugin. However since this is your plugin, there should be nothing preventing you from downloading the file and referencing it locally or linking to it. You should perhaps do so via a document.write after checking to see if jquery exists (so you don't include it again if someone is using simple features, for example). Of course, once jquery is included, you'll have access to Ajax or you can alternatively roll your own XHR functionality.
December 1, 201114 yr Don't think jquery is included unless one uses the simple features GUI plugin. However since this is your plugin, there should be nothing preventing you from downloading the file and referencing it locally or linking to it. You should perhaps do so via a document.write after checking to see if jquery exists (so you don't include it again if someone is using simple features, for example). Of course, once jquery is included, you'll have access to Ajax or you can alternatively roll your own XHR functionality. This.
December 2, 201114 yr Author Don't think jquery is included unless one uses the simple features GUI plugin. However since this is your plugin, there should be nothing preventing you from downloading the file and referencing it locally or linking to it. You should perhaps do so via a document.write after checking to see if jquery exists (so you don't include it again if someone is using simple features, for example). Of course, once jquery is included, you'll have access to Ajax or you can alternatively roll your own XHR functionality. This. I went to your link and read some on the web interface. Very nice. I'm bumping into an error in PHP saying "Fatal error: Call to undefined function json_encode() ". I checked and the PHP version on 5beta13 is "phpinfo() PHP Version => 5.2.13" and any version later than 5.2 is supposed to have json support already compiled in. Did someone take it out for some reason?
December 2, 201114 yr Author Now I'm seeing a problem with the posted parameters not making it to the destination page. scenario: Using Ajax to post from my emhttp/Settings/snap page to /plugins/snap/manageList.php I've tried posting and getting with same result. In firebug on the XHR tab I can see the post has the correct parameters. The manageList.php page gets the posted header and it responds back with an error because the posted $_POST is empty. I also tried just sending in querystring parameters and used $_GET and again firebug shows the parameters being passed but the recieving page never sees them. This tells me that somewhere in emhttp that form and get parameters are being stripped off. With that happening there will be no Ajax possibility. If anyone has insight into a solution around this I'd really appreciate the help. I tested calling this with /plugins/snap/manageList.php?mydata=somedata. It returns the "You didn't send anything" message. Here is my manageList.php code. <?php sleep(3); if (empty($_GET['mydata'])) { $return['error'] = true; $return['msg'] = 'You didn\'t send anything.'; } else { $return['error'] = false; $return['msg'] = 'Result: Good ' . $_GET['mydata'] . '.'; } require_once 'jsonwrapper.php'; echo json_encode($return); ?> Edit 12/3/2011 A simple way to reproduce the problem (without using ajax) is to take that code and make a php file with it. Place that in the plugin of your choice - doesn't matter because it's a simple test. Then browse that page like this: http://tower/plugins/snap/manageList.php?mydata=somedata You will get one of two possible text strings back. If it fails you will get this text: {"error":true,"msg":"You didn't send anything."} If it succeeds you will get this text: {"error":true,"msg":"Result: Good somedata"}
December 5, 201114 yr Can you switch your ajax call to submit doing a "post" (instead of get) as I think you were doing originally. Then on the page that is supposed to receive the posted parameters, try dumping the following variable? e.g. var_dump($argv[1]); If you see some semblance of the parameters you submitted, then you can do the following: parse_str($argv[1], $_POST); and then use the $_POST scope as you would normally.
December 5, 201114 yr Author Can you switch your ajax call to submit doing a "post" (instead of get) as I think you were doing originally. Then on the page that is supposed to receive the posted parameters, try dumping the following variable? e.g. var_dump($argv[1]); If you see some semblance of the parameters you submitted, then you can do the following: parse_str($argv[1], $_POST); and then use the $_POST scope as you would normally. Nice! It works. Thank you.
December 7, 201114 yr Author Now I'm seeing that custom headers aren't being returned in the response from the ajax call back to the page that sent the request. In PHP, no matter how I set the response header back to the caller it is always "HTTP/1.1 200 OK". I would expect that sending a request to a page with only the 3 lines below would return a 404 response. But all I get is "HTTP/1.1 200 OK". <?php header("HTTP/1.0 404 Not Found"); ?> Response Headers HTTP/1.1 200 OK Server: emhttp Cache-Control: no-cache Content-Type: text/html; charset=utf-8 Request Headers POST /plugins/snap/manageList.php HTTP/1.1 Host: 192.168.1.62 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0 Accept: */* Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip, deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Connection: keep-alive Content-Type: application/x-www-form-urlencoded; charset=UTF-8 X-Requested-With: XMLHttpRequest Referer: http://192.168.1.62/Settings/snap Content-Length: 36 Pragma: no-cache Cache-Control: no-cache
December 8, 201114 yr The inbuilt PHP doesn't support much. I use this code from Joe.L, parses any _GET string into an array for you to use. Also some weirdness with special characters, not sure if serializing will help. if (php_sapi_name() =="cli") { $_GET = array(); if (empty($_SERVER["QUERY_STRING"])) { $gg = $argv[1]; } else { $gg = $_SERVER["QUERY_STRING"]; } foreach (explode("&", str_replace("+","%2B",$gg)) as $pair) { list($k, $v) = array_map("urldecode", explode("=", $pair)); $_GET[$k] = $v; } $plugin_home = $_SERVER["PWD"] . '/' . $GLOBALS['myPage']['Root'] . '/'; } else { $plugin_home = dirname($_SERVER["SCRIPT_FILENAME"]) . '/'; }
December 8, 201114 yr Author The inbuilt PHP doesn't support much. I use this code from Joe.L, parses any _GET string into an array for you to use. Also some weirdness with special characters, not sure if serializing will help. if (php_sapi_name() =="cli") { $_GET = array(); if (empty($_SERVER["QUERY_STRING"])) { $gg = $argv[1]; } else { $gg = $_SERVER["QUERY_STRING"]; } foreach (explode("&", str_replace("+","%2B",$gg)) as $pair) { list($k, $v) = array_map("urldecode", explode("=", $pair)); $_GET[$k] = $v; } $plugin_home = $_SERVER["PWD"] . '/' . $GLOBALS['myPage']['Root'] . '/'; } else { $plugin_home = dirname($_SERVER["SCRIPT_FILENAME"]) . '/'; } Thanks. Now I just need for php response headers to work correctly (see my previous post). EDIT 12/8/2011 Here's a simple way to reproduce the problem. Make a test.php with this as it's contents. The <?php has to be at the very top of the file (no spaces in front of it). <?php header("HTTP/1.0 404 Not Found"); ?> stick it in some plugin folder. Then browse with firefox (firebug enabled) to http://tower/plugins/someplugin/test.php. You will get a response header with "HTTP/1.1 200 OK" which is wrong. Here's another fun one. browse to http://tower/nosuchfile.php. Again, you will get a response header of "HTTP/1.1 200 OK". Now try browse to http://tower/nosuchfile.html This time you will get a "HTTP/1.1 404 File not found" So the problem seems to be that sending a request to a php file or browsing a php file will always return a "HTTP/1.1 200 OK" no matter if the php file exists or not.
December 8, 201114 yr Try installing the unMenu PHP package and try it again. I suspect it may be just a severely limited php setup (trying to get Tom to sort this out, currently we cannot use sessions etc).
December 8, 201114 yr Author Try installing the unMenu PHP package and try it again. I suspect it may be just a severely limited php setup (trying to get Tom to sort this out, currently we cannot use sessions etc). I installed the unMenu PHP package and rebooted the machine. The header is still always "HTTP/1.1 200 OK" phpinfo() PHP Version => 5.2.8 System => Linux Tower 3.1.0-unRAID I'm guessing that it's in the Apache configuration.
December 8, 201114 yr Presume it was set to install on reboot? Checkout the httpd.conf file, see what is hidden in there.
December 9, 201114 yr Author Presume it was set to install on reboot? Checkout the httpd.conf file, see what is hidden in there. Yes it reinstalls. Where is httpd.conf? Edit: 12/8/2011 I expected to find it here /etc/httpd/httpd.conf but it's not there or anywhere else. EDIT 12/9/2011 While it's interesting to find out about the header issue, I'm not blocked by it. If I learn anything else about it I'll post back here.
Archived
This topic is now archived and is closed to further replies.