[jQuery] Re: Ajax Data Format Recommendation

2007-05-21 Thread Christopher Jordan
Oops... I typed out my examples too fast. That first example of the data 
parameter should read:


data: "MyVar1=" + myJSVar1 + "&MyVar2=SomeConstantString";

I forgot the ampersand. *sheepish grin*

Cheers,
Chris

Christopher Jordan wrote:

Sam,

Instead of $.get()... I'd use $.ajax().

Check out this post from Brian Ronk 
 
on basically the same subject.


Read my reply (#3), and see if that doesn't help. And while it doesn't 
talk about it, you can also pass arguments as a query string (without 
the leading '?'). The 'data' parameter of the $.ajax function would be 
something like:


data: "MyVar1=" + myJSVar1 + "MyVar2=SomeConstantString";

as opposed to:

data: {"MyVar1":myJSVar1, "MyVar2":"SomeConstantString"}

Also the in-built supported dataTypes in the $.ajax() function are: 
html, json, xml, and script.


Hope this helps. :o)

Cheers,
Chris

SamCKayak wrote:

I did a little Json and some XML using prototype last year.  Now I
have jQuery and need to pass about 4 string parameters to the server,
query a database, and return about 4 string parameters.

My current method to post the get is:

$.get("../survey/postsurveytodb.asp", {
surveyid:   strSurveyId,
question:   strQuestion,
type:   strChoiceType,
choices:strParmChoices
},
function(data){ /* The callback on Ajax Request Complete */
alert("Data Loaded: " + data);
}
);

I am not familiar with any built-in Json support jQuery may have, so
the above method of passing parameters to the server seemed to be
efficent for this request.  ASP can pick apart the query string
neatly.

Json comes to mind when contemplating decoding the return data.  Which
would be easier?  Encoding the data as a query string or as Json.

Suggestions or comments?

Sam


  


--
http://www.cjordan.us


--
http://www.cjordan.us



[jQuery] Re: Ajax Data Format Recommendation

2007-05-21 Thread Christopher Jordan

Sam,

Instead of $.get()... I'd use $.ajax().

Check out this post from Brian Ronk 
 
on basically the same subject.


Read my reply (#3), and see if that doesn't help. And while it doesn't 
talk about it, you can also pass arguments as a query string (without 
the leading '?'). The 'data' parameter of the $.ajax function would be 
something like:


   data: "MyVar1=" + myJSVar1 + "MyVar2=SomeConstantString";

as opposed to:

   data: {"MyVar1":myJSVar1, "MyVar2":"SomeConstantString"}

Also the in-built supported dataTypes in the $.ajax() function are: 
html, json, xml, and script.


Hope this helps. :o)

Cheers,
Chris

SamCKayak wrote:

I did a little Json and some XML using prototype last year.  Now I
have jQuery and need to pass about 4 string parameters to the server,
query a database, and return about 4 string parameters.

My current method to post the get is:

$.get("../survey/postsurveytodb.asp", {
surveyid:   strSurveyId,
question:   strQuestion,
type:   strChoiceType,
choices:strParmChoices
},
function(data){ /* The callback on Ajax Request Complete */
alert("Data Loaded: " + data);
}
);

I am not familiar with any built-in Json support jQuery may have, so
the above method of passing parameters to the server seemed to be
efficent for this request.  ASP can pick apart the query string
neatly.

Json comes to mind when contemplating decoding the return data.  Which
would be easier?  Encoding the data as a query string or as Json.

Suggestions or comments?

Sam


  


--
http://www.cjordan.us



[jQuery] Re: Ajax Data Format Recommendation

2007-05-21 Thread SamCKayak

I found JSON on the return trip to work fine.

Sometimes the answers come to me as soon as I post.

Sam