So for the life of me I can't figure out why my CFC function is not running...firefug says it runs, but nothing happens.
<cffunction name="deleteRequest" access="remote" returntype="void">
<cfargument name="id" type="numeric" required="yes">
<cfquery name = "deleteRequests" datasource = "#application.dsn#">
DELETE FROM requests
WHERE ID = <cfqueryparam cfsqltype="cf_sql_numeric" value = "#id#">
</cfquery>
<cfreturn>
</cffunction>
JQUERY/javascript:
$("input[name=delete]").click(function(){
var z = deleteRequest($(this).attr("id"));
var y = $(this).attr("id");
if(z){
$.ajax({
type: 'POST',
url: '/cfc/request.cfc',
data: {id: y, method: "deleteRequest"}
});
}
});
function deleteRequest(id){
var x = confirm("Are you SURE you want to DELETE this?");
if(x){return 1;}
return 0;
}
The jquery is working...and it is sending it and supposedly getting there...but nothing happens. I tested the CFC and invoked it manually and it works. I'm guessing it is something to do with my variables. I thought maybe the id needed parseInt() but that didn't help either.
All it should do is delete the entry from the DB. What am I doing wrong?
*Sorry for the simple question. I have a lot of troub开发者_运维知识库le with JQUERY+CFC...I have been looking for good tutorials...but I can never seem to find any good beginner ones.
UPDATE: Tried changing url to have the method param in it and changed the access to public...still the same results.
Please try:
<cffunction name="deleteRequest" access="public" returntype="void">
<cfquery name = "deleteRequests" datasource = "#application.dsn#">
DELETE FROM requests
WHERE ID = <cfqueryparam cfsqltype="cf_sql_numeric" value = "#id#">
</cfquery>
<cfreturn>
</cffunction>
$("input[name=delete]").click(function(){
var z = deleteRequest($(this).attr("id"));
var y = $(this).attr("id");
if(z){
$.ajax({
type: 'POST',
url: '/cfc/request.cfc?method=deleteRequest',
data: {id: y}
});
}
});
function deleteRequest(id){
var x = confirm("Are you SURE you want to DELETE this?");
if(x){return 1;}
return 0;
}
We use this style of call quite heavily in our applications with little trouble. Looking at the code, we tend to use the style dknaack suggested, with the method name in the URL but the data supplied as arguments.
Have you tried using Fiddler (fiddler2.com) to intercept the calls to make sure it's definitely calling your code.
Other than that, I' d make use of <CFLOG>
in your method to record what it's being passed, or the debugger if you're set up to use it.
精彩评论