JQuery 数据未正确发送到 CFC

发布于 2024-11-25 05:02:28 字数 1268 浏览 1 评论 0原文

因此,我一生都无法弄清楚为什么我的 CFC 功能没有运行...firefug 说它运行,但没有任何反应。

   <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;
      }

jquery 正在工作...并且它正在发送它并据称到达那里...但没有任何反应。我测试了 CFC 并手动调用它,它可以工作。我猜这与我的变量有关。我想也许 id 需要 parseInt() 但这也没有帮助。

它应该做的就是从数据库中删除该条目。我做错了什么?

*很抱歉问了这个简单的问题。我在使用 JQUERY+CFC 时遇到了很多麻烦...我一直在寻找好的教程...但我似乎永远找不到任何好的初学者教程。

更新:尝试更改 url 以在其中包含方法参数并更改对 public 的访问...仍然是相同的结果。

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 trouble 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

追风人 2024-12-02 05:02:28

请尝试:

<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;
  }

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;
  }
望笑 2024-12-02 05:02:28

我们在应用程序中大量使用这种调用方式,几乎没有什么问题。查看代码,我们倾向于使用 dknaack 建议的样式,方法名称位于 URL 中,但数据作为参数提供。
您是否尝试过使用 Fiddler (fiddler2.com) 来拦截调用以确保它确实在调用您的代码。
除此之外,我会在您的方法中使用 来记录正在传递的内容,或者使用调试器(如果您设置为使用它)。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文