jquery $.ajax to php problem

Posted by Pouya on Stack Overflow See other posts from Stack Overflow or by Pouya
Published on 2010-04-20T14:01:20Z Indexed on 2010/04/20 14:03 UTC
Read the original article Hit count: 435

Filed under:
|
|
|
|

hi.i have two problems with jquery $.ajax. first problem is ihave a php file named action.php and here the code:

if($_GET['action']=='add'){
    //rest of the code here
}

And i use jquery $.Ajax function to call that when form fills:

$.ajax({type:"POST", url:"action.php?action=add", data:$("#form").serialize(), cache:false, timeout:10000});

this works but i wanted to know is there anyway to send the action=add code with data and not the url?

and the second problem that i have is that i have a link:

<a href="#" onclick="delete(4);">delete row from mysql where id is 4</a>

and a jquery function:

    function deleteUser(id){
    $.ajax({type:"POST", url:"action.php?action=delete", data:"id="+id, cache:false, timeout:10000});}

and of course the action.php code:

if($_GET['action']=='deletestudent'){
    mysql_query("DELETE FROM `students` WHERE `student_id` = {$_POST['id']}");
}

but it doesn't work.what should i do?

© Stack Overflow or respective owner

Related posts about php

Related posts about jQuery