Jump to content

netpumber

Members
  • Posts

    107
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

netpumber's Achievements

Member

Member (2/5)

0

Reputation

  1. Yeah i know that, but i don't know how to parse the Arrays inside that json object. To print out the status i can write this : $('#info').val(json.status) but how can i write down data from the arrays in the form i wrote before ?
  2. Hello. Server returns this json {"status":1,"job_status":"READY","iterations":["Contig2","Contig75"],"accessions":["NP_001061702","NP_001068174"]} And i would like to print out in a textarea (using the above jQuery command) $('#info').val() something like this: Contig2 : NP_001061702 Contig75 : NP_001068174 Any idea on how to achieve this? Thanks!
  3. Hmm i created a global var $aR = ''; then in the // Submit Data to ncbi. // Sends form's data to classController.php function NCBI_submit_data() { $formData = $('#blastx_form').serialize(); $php_method = 'ncbi_request'; $finalData = $formData + "&php_method=" + $php_method; $aR = ajaxReq('POST','../../classes/classController.php',$finalData,'json'); console.log($aR); } // General Ajax function function ajaxReq($method,$url,$data,$dataType) { $.ajax({ type: $method, url: $url, async: 'false', data: $data, dataType: $dataType, success: function(json, textStatus, jqXHR) { $aR = json; }, error: function(jqXHR, textStatus, errorThrown) { console.log('Ajax call error: '+jqXHR.status+' '+errorThrown) } }); } But doesn't seem to work.
  4. Hi! I have this code above: // Submit Data to ncbi. // Sends form's data to classController.php function NCBI_submit_data() { $formData = $('#blastx_form').serialize(); $php_method = 'ncbi_request'; $finalData = $formData + "&php_method=" + $php_method; $aR = ajaxReq('POST','../../classes/classController.php',$finalData,'json'); console.log($aR); } // General Ajax function function ajaxReq($method,$url,$data,$dataType) { $.ajax({ type: $method, url: $url, async: 'false', data: $data, dataType: $dataType, success: function(json, textStatus, jqXHR) { return json; }, error: function(jqXHR, textStatus, errorThrown) { console.log('Ajax call error: '+jqXHR.status+' '+errorThrown) } }); } Server returns a json object and i want to save it in aR variable. But console.log($aR); returns undefined Any idea on how to fix it ?
  5. Ok! i chown and chgrp it for user http and now seems to work.
  6. the output of ls -la. and i'm using Arch linux.
  7. I changed the path but im still getting this error :
  8. Finally with ZAP tool found that the upload.php file returns this : upload directory has 777 permissions and chowned to http user , but the message id still produced .
  9. Yes i know what error code 3 means but the weird thing is that the server and the client is the same PC in both cases. Either if i'm running the application locally (127.0.0.1) or running it through the web (e.g www.blahblah.com). I cannot find a reason for the connection to timeout/lost , every time i'm trying it.
  10. Hello! I have a problem with uploading some files from my web app, when i m running it through Apache's document root. Let's take it from the beginning. I have create a vhost where all the files of my web app are there. Here is the vhost directive of apache's config <VirtualHost 127.0.0.1:80> DocumentRoot "/home/n3t/dev/http/geneBank/" ServerName dev.geneBank ServerAlias dev.geneBank ErrorLog "/var/log/httpd/VHost-geneBank/error_log" CustomLog "/var/log/httpd/VHost-geneBank/access_log" common <Directory /home/n3t/dev/http/geneBank/> DirectoryIndex index.htm index.html index.php Options ExecCGI Indexes FollowSymLinks MultiViews Includes AllowOverride All Order allow,deny allow from all Require all granted </Directory> </VirtualHost> and here is the php file that uploads files. <?php error_reporting(E_ALL); ini_set('display_errors', '1'); // A list of permitted file extensions $allowed = array('png', 'jpg', 'gif'); // Check if a rec id has sent and creates a directory with its name. if($_POST['uplRecID'] != ''){ //Check if the given RecId is valid by begining with 'PL'. $str = substr($_POST['uplRecID'], 0, 2); if($str == 'PL'){ // Check if the directory allready exists. if(!file_exists("uploads/".$_POST['uplRecID'])){ echo " Dir didn't exist and we create it now.."; if(!mkdir("uploads/".$_POST['uplRecID'], 0777)){ echo '{"status":"error creating the dir"}'; } } }else{ echo '{"status":"Unaccepted recID"}'; exit; } } if(isset($_FILES['upl']) && $_FILES['upl']['error'] == 0){ $extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION); if(!in_array(strtolower($extension), $allowed)){ echo '{"status":"Unaccepted extension"}'; exit; } if(move_uploaded_file($_FILES['upl']['tmp_name'], 'uploads/'.$_POST['uplRecID'].'/'.$_FILES['upl']['name'])){ echo '{"status":"success"}'; exit; } }else{ echo $_FILES['upl']['error']; echo '{"status":"error"}'; exit; } ?> So, when im running this code from dev.geneBank (Vhost) everything works like a charm. But when i move that code into apache's document root (/var/www/httpdocs/) directory and run it through the web (not locally) , $_FILES['upl']['error'] returns error with number 3. So i thought that maybe the fault is that document root isn't configured for file uploading. If i am correct, is there any way to configure the document root using .htaccess file ? I don't want to change the main httpd.conf file. Thank you.
  11. Hi! Server sends such a json object: {"status":1,"recId":"PL-17534","collectionDate":"08-04-2014","collectorsName":"asdf","donorsName":"","sciName":"asdf","family":"asdf","comName":"asdf","variety":"","area":"asdf","photoFiles":["1.jpg","internet.jpg"]} So i want to change the html content of an element , by customizing the contents of json object in the photoFiles array. I tried something like this but doesn't seem to work $('#photosTab').html(function(){ $.each(json.photoFiles, function(i,item){ return '<img src="'+json.photoFiles[0]+'"><br>'; }) }); Any idea ?
  12. Hello guys. I have a file with the above function that returns the $db variable. function mysql_init(){ $db = new PDO('mysql:host=localhost;dbname=geneticDb;charset=utf8', 'dev', 'dev'); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); return $db; } Now i want to use this variable in every method of the above class without call again that function in each method. Somehow i want to call this once and then just use the $db variable. <?php require_once('mysql.php'); class Note { private $_done; private $_noteType; private $_plantId; private $_noteTitle; private $_noteText; private $_regenerationDate; private $_noteId; public function __construct() { } public function addNote($noteType, $plantId , $noteTitle, $noteText) { $this->_noteType = $noteType; $this->_plantId = $plantId; $this->_noteTitle = $noteTitle; $this->_noteText = $noteText; $db = mysql_init(); $sql = "INSERT INTO notes ( noteId , noteType, plantId, noteTitle, noteText ) VALUES ('', ?, ?, ?, ?)"; $prq = $db->prepare($sql); $prq->bindValue(1,$this->_noteType, PDO::PARAM_STR); $prq->bindValue(2,$this->_plantId,PDO::PARAM_INT); $prq->bindValue(3,$this->_noteTitle,PDO::PARAM_STR); $prq->bindValue(4,$this->_noteText,PDO::PARAM_STR); ($prq->execute()) ? $this->_done = 1 : $this->_done = 0; if ($this->_done == '0') { $json = array('status' => $this->_done, 'error' => $prq->errorCode() ); $JsonObject = json_encode($json); }else{ $json = array('status' => $this->_done); $JsonObject = json_encode($json); } echo $JsonObject; } public function addRegenerationNote($noteType, $plantId , $regenerationDate) { $this->_noteType = $noteType; $this->_plantId = $plantId; $this->_regenerationDate = $regenerationDate; $db = mysql_init(); $sql = "INSERT INTO notes ( noteId , noteType, plantId, regenerationDate ) VALUES ('', ?, ?, ?)"; $prq = $db->prepare($sql); $prq->bindValue(1,$this->_noteType,PDO::PARAM_STR); $prq->bindValue(2,$this->_plantId,PDO::PARAM_INT); $prq->bindValue(3,$this->_regenerationDate,PDO::PARAM_STR); ($prq->execute()) ? $this->_done = 1 : $this->_done = 0; if ($this->_done == '0') { $json = array('status' => $this->_done, 'error' => $prq->errorCode() ); $JsonObject = json_encode($json); }else{ $json = array('status' => $this->_done); $JsonObject = json_encode($json); } echo $JsonObject; } ..... As you can see i call in every method the mysql_init() function. Is it possible to call it only once at the start of the class and then just use the $db var ? Thank you.
  13. I have this php code for counting the pages number and retrieve data from database, but something is going wrong with the pager as i can see. Specifically i think that there is a problem with the json file structure. Here is the php code: public function getLogsList($page,$limit,$sidx,$sord) { init_mysql(); $return_array = array(); $row_array = array(); // Getting pages number (for jqGrid pager) if(!$sidx) $sidx =1; $result = mysql_query("SELECT COUNT(*) AS count FROM logs"); $row = mysql_fetch_array($result); $count = $row['count']; if( $count >0 ) { $total_pages = ceil($count/$limit); } else { $total_pages = 0; } if ($page > $total_pages) $page=$total_pages; $start = $limit*$page - $limit; $row_array['page'] = $page; $row_array['total'] = $total_pages; $row_array['records'] = $count; array_push($return_array,$row_array); // Getting data for jqGrid table $data = mysql_query("SELECT * FROM logs ORDER BY log_id DESC"); if(mysql_num_rows($data)) { while($row = mysql_fetch_array($data)) { $row_array['log_id'] = $row['log_id']; $row_array['ip'] = $row['ip']; $row_array['hostname'] = $row['host']; $row_array['log'] = $row['input']; $row_array['date'] = $row['date']; array_push($return_array,$row_array); } } echo json_encode($return_array); } The json file looks like this : [{"page":"1","total":2,"records":"34"},{"page":"1","total":2,"records":"34","log_id":"108","ip":"127.0.0.1","hostname":"","log":"having 1=1","date":"09-06-2013 22:05:57"},{"page":"1","total":2,"records":"34","log_id":"107","ip":"127.0.0.1","hostname":"","log":"\/\/","date":"09-06-2013 22:05:57"},.....}] as you can see page , total and records are printed every time and thats why i think that something is going wrong with the structure of json file. I saw in a forum that the json file must have this structure but i cannot make it look like this { "page": "1", "total": 1, "records": "6", "rows": [ { "head": { "student_name": "Mr S. Jack ", "year": 2007 }, "sub": [ { "course_description": "Math ", "date": "22-04-2010", "number": 1, "time_of_add": "2:00", "day": "today" } ] } ] } Can you help me on this issue ? Thanks in advance
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.