[jQuery] Re: Ajax not sending data correctly when it's a variable, but perfect when it the value is typed in instead.
I don't know PHP at all, but it appears $_GET["prefix"] is the syntax Got that from: http://drupal.org/node/120723
[jQuery] Re: Ajax not sending data correctly when it's a variable, but perfect when it the value is typed in instead.
You're right, the values transferred fine without doing anything to them. Could you show me a method that will accept Request.Params just like I'm trying to get this data? On Sep 19, 12:51 pm, MorningZ <[EMAIL PROTECTED]> wrote: > " Which is weird because with a .NET backend, it HAS to be a string" > > Which is totally not true .NET can handle JSON in (via > Request.Params) and JSON out (using the excellent JSON.net class by > James Newton King) > > anyways, If you have > > var OBJ = {}; > $(":input").each( function () { > OBJ[$(this).attr("name")] = $(this).val(); > > }); > > $.ajax({ > url: "setBMBJSONString.php", > data: OBJ, > .. etc etc... > > }); > > Then the receiving page, no matter if it's php. .NET, whatever, will, > well *should*, see properly encoded/escaped Key/Value pairs as either > QueryString or Form pairs (depending on if the $.ajax call does GET or > POST) watch the call in firebug and keep an eye on the Params or > Post tab in the Console and you can confirm/deny this > > You shouldn't need to scrub those at all... if it's anything else, > then you aren't coding all this correctly... perhaps if you get a live > and testable page up for others to dissect? > > On Sep 19, 1:04 pm, Namlet <[EMAIL PROTECTED]> wrote: > > > Yes, same result. I added the toString() just in case. I've > > discovered more. Here is the code right before it that makes the > > variable: > > > var OBJ = {}; > > $(":input").each( function () { > > OBJ[$(this).attr("name")] = $(this).val(); > > }); > > var stringJSON = JSON.stringify(OBJ); > > > Now if I pass OBJ to the data: parameter it works! Unfortunately, > > double quotes make it break, etc. so I really need to have it scrubbed > > before sending it, which JSON.stringify is supposed to do. So it > > looks like it doesn't like strings. Which is weird because with > > a .NET backend, it HAS to be a string. I wish I new more about what > > was going on there. > > > How can I do this? Do I have to write my own scrubbing?? And why > > doesn't it like strings? > > > On Sep 19, 11:56 am, MorningZ <[EMAIL PROTECTED]> wrote: > > > > have you tried: > > > > data: stringJSON > > > > (without the "toString()" ?)
[jQuery] Re: Ajax not sending data correctly when it's a variable, but perfect when it the value is typed in instead.
" Which is weird because with a .NET backend, it HAS to be a string" Which is totally not true .NET can handle JSON in (via Request.Params) and JSON out (using the excellent JSON.net class by James Newton King) anyways, If you have var OBJ = {}; $(":input").each( function () { OBJ[$(this).attr("name")] = $(this).val(); }); $.ajax({ url: "setBMBJSONString.php", data: OBJ, .. etc etc... }); Then the receiving page, no matter if it's php. .NET, whatever, will, well *should*, see properly encoded/escaped Key/Value pairs as either QueryString or Form pairs (depending on if the $.ajax call does GET or POST) watch the call in firebug and keep an eye on the Params or Post tab in the Console and you can confirm/deny this You shouldn't need to scrub those at all... if it's anything else, then you aren't coding all this correctly... perhaps if you get a live and testable page up for others to dissect? On Sep 19, 1:04 pm, Namlet <[EMAIL PROTECTED]> wrote: > Yes, same result. I added the toString() just in case. I've > discovered more. Here is the code right before it that makes the > variable: > > var OBJ = {}; > $(":input").each( function () { > OBJ[$(this).attr("name")] = $(this).val(); > }); > var stringJSON = JSON.stringify(OBJ); > > Now if I pass OBJ to the data: parameter it works! Unfortunately, > double quotes make it break, etc. so I really need to have it scrubbed > before sending it, which JSON.stringify is supposed to do. So it > looks like it doesn't like strings. Which is weird because with > a .NET backend, it HAS to be a string. I wish I new more about what > was going on there. > > How can I do this? Do I have to write my own scrubbing?? And why > doesn't it like strings? > > On Sep 19, 11:56 am, MorningZ <[EMAIL PROTECTED]> wrote: > > > have you tried: > > > data: stringJSON > > > (without the "toString()" ?)
[jQuery] Re: Ajax not sending data correctly when it's a variable, but perfect when it the value is typed in instead.
Yes, same result. I added the toString() just in case. I've discovered more. Here is the code right before it that makes the variable: var OBJ = {}; $(":input").each( function () { OBJ[$(this).attr("name")] = $(this).val(); }); var stringJSON = JSON.stringify(OBJ); Now if I pass OBJ to the data: parameter it works! Unfortunately, double quotes make it break, etc. so I really need to have it scrubbed before sending it, which JSON.stringify is supposed to do. So it looks like it doesn't like strings. Which is weird because with a .NET backend, it HAS to be a string. I wish I new more about what was going on there. How can I do this? Do I have to write my own scrubbing?? And why doesn't it like strings? On Sep 19, 11:56 am, MorningZ <[EMAIL PROTECTED]> wrote: > have you tried: > > data: stringJSON > > (without the "toString()" ?)
[jQuery] Re: Ajax not sending data correctly when it's a variable, but perfect when it the value is typed in instead.
have you tried: data: stringJSON (without the "toString()" ?)