我已经尝试了很多不同的选项来发送json数据到一个cfc而不使用jquery,我的问题是如何使用XMLHttpRequest()而不是$ .ajax来完成?它将请求发送给CFC,但我不能将任何变量传递给cfc,它一直说“FORMDATA”(这是我的不传入),我有一个称为表单数据的变量。我能够实现它的唯一方法是使用新的formData()对象,但我需要它在IE 8和9中工作?有没有办法使用XMLHttpRequest()将json发送到远程cfc?
<cfcomponent>
<cffunction name="validate" access="remote" >
<cfargument name="formdata" required="true" type="string"/>
<!--- <cfif isJSON(arguments.formdata)>
<cfset values = deserializeJSON(arguments.formdata)>
</cfif> --->
<cfdump var="#variables#">
<cfdump var="#arguments#">
<cfreturn { STATUS = 200, MESSAGE = "data recieved"}>
</cffunction>
</cfcomponent>
这里是我的javascript
var xhr = new XMLHttpRequest();
xhr.open("POST", "validation.cfc?method=validate", true);
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
// send the collected data as JSON
xhr.send(JSON.stringify({formdata:data}));
xhr.onloadend = function() {
console.log(xhr.responseText);
};
我不知道我做错了吗?
标题不代表您真正的问题。 –
我很抱歉我重新写了标题 – Jesse