Sent from my LG Mobile
bige...@gmail.com wrote:
>hello
>
>if we use chrome or firefox we can't successfully get the jquery ajax post
>data,
>
>but we found if we use ie9 or ie8 to send POST data by jquery ajax ,
>node.js just receive empty body {}
>
>even we change the header like content-type to application/json or
>text/plain and Accept value it still didn't work
>
>so is here anyone have the same problem or have any solution , please help
>me thanks a lot
>
>i paste my code below
>
>-------------------------------------------
>
>if(jQuery.browser.msie && window.XDomainRequest) {
>
> //var data=JSON.stringify({'property_id':'50da64f65d396b1e48000001','name':'222','start_date':'2012/11/11'});
> var data='property_id=50da64f65d396b1e48000001&id=222';
>
> var xdr = new XDomainRequest();
> xdr.contentType= 'text/plain';
>
> xdr.onload = function (e) {
> var data = $.parseJSON(xdr.responseText);
> if (data == null || typeof (data) == 'undefined') {
> alert(data)
> }
> //success
> };
> xdr.onerror = function (e) {
> //alert(e);
> }
>
> xdr.open("POST", url);
> xdr.send(data);
>
> }
> else
> {
> $.post(url,{'property_id':'111','name':'222','start_date':'2012/11/11'}, function(data) {
> alert(data)
> });
> }
>
>
>---------------------------------------------------
>
>
>$.ajax({
> beforeSend: function(xhrObj){
> xhrObj.setRequestHeader("Content-Type","application/json");
> xhrObj.setRequestHeader("Accept","application/json");
> }
> url: url,
> type: "POST",
> data: JSON.stringify({'property_id' : 'test'}),
> headers : {
> 'Accept' : 'application/json',
> 'Content-Type' : 'application/x-www-form-urlencoded'
> },
> dataType: "json",
> success: function(data){
> alert(data);
> }
>});
>
>--
>Job Board: http://jobs.nodejs.org/
>Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
>You received this message because you are subscribed to the Google
>Groups "nodejs" group.
>To post to this group, send email to nod...@googlegroups.com
>To unsubscribe from this group, send email to
>nodejs+un...@googlegroups.com
>For more options, visit this group at
>http://groups.google.com/group/nodejs?hl=en?hl=en
app.all('*', function(req, res, next) {res.header("Access-Control-Allow-Origin", "*");res.header("Access-Control-Allow-Headers", "X-Requested-With");res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");res.header("X-Powered-By",' 3.2.1')res.header("Content-Type", "application/json;charset=utf-8");if(req.method==='OPTIONS')res.send(200);elsenext();});and we sure we have no cross origin problemso is there any possible ajax wrong or node.js setting needed to adjust?and thanks a lot john~
app.all('*', function(req, res, next) {res.header("Access-Control-Allow-Origin", "*");res.header("Access-Control-Allow-Headers", "X-Requested-With");res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");res.header("X-Powered-By",' 3.2.1')res.header("Content-Type", "application/json;charset=utf-8");if(req.method==='OPTIONS')res.send(200);elsenext();});
Hello,I actually had/have the same problem. It is not node.js at the backend, but getting the f***** IE 8 to send an ajax request to a different target is a mess, regardless of the receiver.Your response looks good, quite similar to mine. My jQuery.ajax looks like this:jQuery.ajax({
url: planview_bridge_host + 'order_number',
dataType: 'json',
data: "{\"code\": \"" + id + "\", \"order_number\": \"" + order + "\"}",
headers: {
x_auth_user: 'dirk',
x_auth_password: 'password',
x_method: 'DELETE'
},
contentType: 'application/json; charset=UTF-8',
type: 'POST',
success: function(data) {
if (data) {
setToNein();
return updateOrderNumber('undef');
} else {
return alert('Falsche Daten empfangen: ' + JSON.stringify(data));
}
},
error: function(jqXHR, textStatus, e) {
alert(JSON.stringify(jqXHR));
setToJa();return alert('Verbindungsproblem: ' + JSON.stringify(e));
}
});(The JSON object is not present in IE8 by default, I added the json2.js by Crockford to the page)Actually I added: "jQuery.support.cors = true" in my client script. And read somewhere that some browsers are unable to send requests with methods other than POST and GET. So I reverted to POST everything and send the method really meant as a custom header field ("x_method").It works despite the fact that when a user for the first time tries to send a request, he is asked if he truly want to send data to a different host.Hope it helps a little.RegardsDirk