jquery - How does php handle ajax post request -


maybe not smart think having issues ajax , php interacting each other. trying make save method.

this php have. guess not checking right things.

(this page called edit.php)

<?php if(isset($_post['text']) && isset($_get['dir'])){    $file = $_post['location'];     $handle = fopen($file, 'w') or die("can't open file");    $data = $_post['text'];     fwrite($handle, $data);     fclose($handle);  }  ?> 

<input type="text" value="<?=$_get['dir'];?>" id="savevalue"> function gets called when push ctrl , s

    function savefile(){ var data = new formdata();     data.append('text', e.getsession().getvalue());     data.append('location',$('#savevalue').val()); var url = $('#savevalue').val();  var split = url.split('/public_html');      alert(split[1]); var url = "edit.php?dir="+split[1];   $.ajax({     url: url,     type: "post",     data: data,      success: function (data, textstatus, jqxhr) {         if (data == "false") {             console.log("there problem on server, please try again later");             } else {                 //do returned                 console.log("failed");         }     } });       }; 

i think either checking wrong thing or not submitting think am. may please or @ least clarification on this.

i have read need use $_request['text'] instead of $_post neither have worked.

imo trying mix 2 request types get post.

in ajax call url specify doesn't contain dir parameter, consequence condition isset($_post['text']) && isset($_get['dir']) fails.

you cannot have edit.php?dir=foo because can have request method either get or post`

your server side script has if() condition check post parameters. suggested @marcel gwerder if(isset($_post['text']) && isset($_post['location']))

happy help.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -