Reputation: 4712
I am trying to send a simple ajax post request using Mootools but I'm only receiving the error message in the title and it seems it doesn't send the data correctly (the request gets canceled).
Here is the html:
<form id="form_5" name="form_5" action="someajaxfile.php" onsubmit="jsfunction(this,5);return false;" method="post">....</form>
And here is the javascript function called when submitted:
function jsfunction(form,eventId) {
var container = $('form_contents' + eventId);
form.send({
update: container,
evalScripts: true,
onComplete: function() {
container.removeClass('ajax-loading');
}
});
}
I've tried to add stuff like headers: {'X-Request': 'JSON'},
to the send function but nothing seems to change the error. One wierd thing is tho, that in chrome under the network tab I can see two requests:
someajax.php
/somefolder
POST
302
Found
text/html
mootools.js:247
Script
354B
0B
2ms
2ms
2ms0
someajax.php
/somefolder
GET
(canceled)
Pending
http://localhost:8888/somefolder/someajax.php
Redirect
13B
0B
0ms
0.0 days
The question is: why can't I send the data, what happens and why and it there any good solution to my problem?
Upvotes: 1
Views: 2659
Reputation: 20102
hmmm After trying a few things, I dont think its possible to make an "AJAX" request directly from the form element (but if I'm wrong I'd like to see an example of how that works n_n)
Usually I use an instance of Request (or any of it's extensions: Request.JSON, Request.JSONP, Form.Request).
I'd do it like this:
function myfunction(form){
new Request({
url:form.action,
data:form,
onSuccess:function(result){
console.log(result);
}
}).send();
return false;
};
A working example here: http://jsfiddle.net/pCUKe/
Upvotes: 1
Reputation: 9010
The question is: why can't I send the data, what happens and why and it there any good solution to my problem?
Your problem is the combination of Chrome+Local and the --allow-file-access-from-files restriction.
To try:
Upvotes: 1