Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

php - Posting not working via JS (Jquery) but is with form -


i have rather confusing problem.

i have php file (http://example.com/delete.php)

<?php session_start();  $user_id = $_session['user_id']; $logged_in_user = $_session['username']; require_once('../classes/config.php'); require_once('../classes/post.php'); $post = new post(null,$_post['short']); #print_r($post); try {  if ($post->user_id == $user_id) {   $pdo = new pdoconfig();          $sql = "delete posts id=:id";     $q = $pdo->prepare($sql);    $q->execute(array(':id'=>$post->id));           $pdo = null;  }  else {throw new exception('false');} }        catch (exception $e) {    echo 'false'; } ?> 

and i'm trying jquery post data it, , delete data.

$('.post_delete').bind('click', function(event) {      var num = $(this).data('short');      var conf = confirm("delete post? (" + num + ")");      if (conf == true) {         var invalid = false;         $.post("http://example.com/delete.php", {short: num},         function(data){              if (data == 'false') {                 alert('deleting failed!');                 invalid = true;             }         });          if (invalid == false) {            alert("post has been deleted!");         }          else {             event.preventdefault();             return false;         }       }      else {         event.preventdefault();         return false;     }    }); 

and when that, returns "post has been deleted!" not delete post.

confused that, made form test php.

<form action="http://example.com/delete.php" method="post"> <input type="hidden" value="8" name="short"/> <input type="submit" name="submit" value="submit"/> </form> 

which works beautifully. odd.

i have code identical deleting of comment, , works great in javascript.

any ideas? beats me.

thanks in advance, will

edit: works... doesn't follow href @ end, desired effect. odd.

$('.post_delete').bind('click', function(event) {      var num = $(this).data('short');      var conf = confirm("delete post? (http://lala.in/" + num + ")");      if (conf == true) {         var invalid = false;         $.post("http://example.com/delete/post.php", {short: num},         function(data){              if (data == 'false') {                 alert('deleting failed!');                 invalid = true;             }         });          if (invalid == false) {            alert("post has been deleted!");         ******************************************             event.preventdefault();             return false;         ******************************************         }          else {             event.preventdefault();             return false;         }       }      else {         event.preventdefault();         return false;     }       }); 

if php script delete post, doesn't return anything.


my bad, it's not answering real question, still mistake ;)

actually, seems php session , ajax doesn't quite work sometimes.

it means if ($post->user_id == $user_id) never validate, hence non-deleting problem.

2 ways see :

  1. log $user_id , see if it's not null
  2. try send $_session['user_id'] ajax post , check it. not in production, security reason.

1-

your php should return in every case (at least, when you're looking bug actual case).

<?php [...] try {  if ($post->user_id == $user_id) {   [...]   echo 'true';  }  else {throw new exception('false');} }        catch (exception $e) {    echo 'false'; } ?> 

2-

jquery nice use ajax many reasons. example, handles many browsers , make checks moreover, can handle success , error in same .ajax() / .post() / .get() function \o/

$('.post_delete').bind('click', function(event) {     var num = $(this).data('short'); // if that's data is... fair enough.     if (confirm("delete post? (http://lala.in/" + num + ")")) {         $.post("delete/post.php", {short: num}, // relative nice :d         function(data){             if (data == 'false') {                 alert('deleting failed!');              }else{                 alert("post has been deleted!");                 // redirection here ?             }         });      } }); 

3-

if need send data form script , redirection, i won't recommand ajax use not leave page ! therefore, should what's in comment, form php script apparently delete , redirection.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -