我正在通过一个教程来实现一个可排序的列表,我无法判断是否正在加载json。有没有办法使用Firebug和Firequery来查看它是否被调用或者它是否是一个糟糕的地址?我没有看到任何错误。我的HTML和Coldfusion:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<link rel="stylesheet" href="../css/jquery-ui.css" />
<script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>
<script type="text/javascript">
$(function() {
$sortable = $("#sortable").sortable({
update: function(event, ui){
updateOrder();
}
}).disableSelection();
function updateOrder(){
$.getJSON(
'remote.cfc?wsdl',
{
method : 'updateOrder',
key: '<cfoutput>#session.ajaxkey#</cfoutput>',
orderedList: $sortable.sortable('toArray').toString(),
returnformat: 'json',
queryformat: 'column',
},
callback
);
}
});
function callback(json){
if ( json.RESULT )
{
$('#serverresult').text( "Order updated to: " + json.NEWORDER );
}
else
{
$('#serverresult').text( "Something went wrong!" );
}
}
</script>
</head>
<body>
<body>
<h1>Menu List</h1>
<cfquery name="rsSort" datasource="#DataSource#">
SELECT * FROM `test-sort` ORDER by Sort
</cfquery>
<div class="demo">
<ul id="sortable">
<cfoutput>
<cfloop query="rsSort">
<li id="id_#ID#">#Title# #ID#</li>
</cfloop>
</cfoutput>
</ul>
<div id="serverresult">
</div>
</div>
</body>
</html>
被调用的文件:
<cfcomponent output="false" hint="I respond to AJAX requests">
<cffunction name="updateOrder" output="false" access="remote">
<cfargument name="orderedList" required="true" type="string">
<cfargument name="key" required="true" type="string">
<cfset var ndx = "">
<cfset var id = 0>
<cfset var position = 0>
<cfset var updatedids = "">
<cfset var result = {result="false"}>
<!--- do a basic security check --->
<cfif isAllowed( arguments.key )>
<!--- Prevent race conditions --->
<cflock name="updateOrder" timeout="60">
<cftransaction>
<cfloop list="#arguments.orderedList#" index="ndx">
<cfset id = Val( ListLast( ndx, "_" ) )>
<cfset position = position+1>
<cfset updatedids = ListAppend( updatedids, id )>
<cfquery datasource="#DataSource#">
update `test-sort` set
Sort = <cfqueryparam value="#position#" cfsqltype="cf_sql_integer">
where
id = <cfqueryparam value="#id#" cfsqltype="cf_sql_integer">
</cfquery>
</cfloop>
<!--- delete any items not in the list --->
<cfquery datasource="#DataSource#">
delete from `test-sort`
where id not in ( <cfqueryparam value="#updatedids#" cfsqltype="cf_sql_integer" list="true"> )
</cfquery>
</cftransaction>
</cflock>
<cfset result = {result="true", neworder=updatedids, position=position }>
</cfif>
<cfreturn result>
</cffunction>
<cffunction name="isAllowed" output="false" access="private" returntype="boolean">
<cfargument name="key" required="true">
<cfset var result = false>
<!--- check that request is coming from the same browser that created the session --->
<cfif IsDefined( "session.ajaxkey" ) AND ( session.ajaxkey eq arguments.key )>
<cfset result = true>
</cfif>
<cfreturn result>
</cffunction>
</cfcomponent>
答案 0 :(得分:0)
你几乎肯定不想在你正在使用的URL中使用?wsdl。那将只返回您的CFC的WSDL XML。希望Firebug会证明这一点。您还可以使用Fiddler调试网络流量(适用于所有浏览器)
您可能还需要在cffunction中设置returnformat =“JSON”,以便让CF将您返回的结构转换为JSON。
答案 1 :(得分:0)
使用?wsdl
对我有用,我认为你的回调中的第一行应该是:
var JSON=jQuery.parseJSON(json);
然后在此函数中使用JSON而不是json。