Jump to content


Photo

.post to .ajax


  • Please log in to reply
5 replies to this topic

#1 azraelGG

azraelGG

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 21 January 2013 - 06:50 AM

can anyone help me convert post to ajax
i want use beforesend option but its only avaliable in .ajax method

this is post i want edit
function ajaxDelete(id, tablica, tablica_col, trID){
  var current = $(trID).closest('tr');//.attr('id');
   if(confirm("Potvrdite brisanje")){
    $.post("ajax/ajaxDelete.php", {id: id, tablica: tablica, tablica_col: tablica_col }, function(data){
	
    });
    beforeSend: current.animate({'backgroundColor':'#fb6c6c'},300);
   }
};

and calling
<td><a class="deleteReccord" style="cursor:pointer;" onclick="ajaxDelete('.$stroj['stroj_ID'].', \'stroj\', \'stroj_ID\',this);">Obriši</a></td>


#2 Christian F.

Christian F.

    Advanced Member

  • Staff Alumni
  • 3,106 posts
  • LocationNorway

Posted 21 January 2013 - 07:50 AM

No need to use AJAX for this. Just return true or false from the function, depending whether or not you want the form to be submitted. You'll have to associate the function with the "onsubmit" handler for the form, and return the value returned from the function, in order to properly halt the submission of the form:
<form method="post" onsubmit="return confirmDelete()"....

You can also use the .preventDefault() method of the event.
Keeping it simple.

#3 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 21 January 2013 - 08:36 AM

He's already using Ajax. He's asking how to switch from jquery's ".post" to ".ajax"
Which should be easy by reading the manual.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#4 stijn0713

stijn0713

    Advanced Member

  • Members
  • PipPipPip
  • 231 posts

Posted 21 January 2013 - 01:04 PM

can anyone help me convert post to ajax
i want use beforesend option but its only avaliable in .ajax method


I think you meant you want to use post instead of ajax?
as you say, beforeSend is only available to .ajax(). Why would you use .post() then?

Anyway, i think there are only 2 options, either you use .ajax(), else you use ajaxSetup as it applies to all ajax requests:
$.ajaxSetup({
beforeSend: myFunc,
});

Edited by stijn0713, 21 January 2013 - 01:05 PM.


#5 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 21 January 2013 - 01:08 PM

I think you meant you want to use post instead of ajax?
as you say, beforeSend is only available to .ajax(). Why would you use .post() then?


Seriously??

This thread is like watching a Three Stooges sketch.
Or Abbott and Costello. 
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#6 stijn0713

stijn0713

    Advanced Member

  • Members
  • PipPipPip
  • 231 posts

Posted 21 January 2013 - 01:18 PM

Seriously??

This thread is like watching a Three Stooges sketch.
Or Abbott and Costello.


haha, now i realize my misinterpretation :). Probably because the answer is too obvious. Anyway, i don't know the three stooges so can't laugh along with you...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com