[jQuery] How can I make sure one AJAX call returns before another?

2008-09-22 Thread Namlet

I have several AJAX calls.  Most of them retrieve values for drop-down
lists and one fills in the data.  Of course, unless the drop down
lists are fully loaded, the data filler doesn't select them properly.
Is there anyway to trigger the data filler after they are complete
with more sophistication than setTimeout?

BTW, I've tried ajaxStop but that causes an infinite loop since the
data filler triggers it again.

Thanks!



[jQuery] Ajax not sending data correctly when it's a variable, but perfect when it the value is typed in instead.

2008-09-19 Thread Namlet

I have a simple AJAX call:

$.ajax({
url: setBMBJSONString.php,
data: stringJSON.toString(),

success: function(rdata) {
//var resp = eval('(' + rdata + ')');
$(body).append(rdata);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
var e = XMLHttpRequest;
for (var key in e) {
$(body).append(key + :  + e[key] + br /);
}
}
});

That won't work, the data doesn't get to the webservice that way.  But
if I do this instead:

$.ajax({
url: setBMBJSONString.php,
data:
{prefix:Bishop,fname:Nkulu,mname:Ntanda,lname:Ntambo,suffix:Esq.,relation:},
success: function(rdata) {
//var resp = eval('(' + rdata + ')');
$(body).append(rdata);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
var e = XMLHttpRequest;
for (var key in e) {
$(body).append(key + :  + e[key] + br /);
}
}
});

Everything works fine!  All I did was print out stringJSON and copy it
and paste it in there.  What's going on?  For obvious reasons I need
to use a variable there.





[jQuery] Re: Ajax not sending data correctly when it's a variable, but perfect when it the value is typed in instead.

2008-09-19 Thread Namlet

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.

2008-09-19 Thread Namlet

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] Simple question about Radio Buttons

2008-09-19 Thread Namlet

Why does this line of code not work for the radio button?

if ($(this).attr(type) == radio) alert($(this).checked);

I get 6 alert boxes (I have 6 Radio Buttons) and the alert says
undefined every time.  But half of them should be true and half should
be false.  Am I doing something wrong?

here are two of the radios:

input name=recvd_loan type=radio value=1 / Yes
input name=recvd_loan type=radio value=0 / No

Thanks!


[jQuery] Re: Simple question about Radio Buttons

2008-09-19 Thread Namlet

Well I fixed it, I had to use:

$(this).attr(checked)

to get the value.  Should I have known this?


On Sep 19, 2:48 pm, Namlet [EMAIL PROTECTED] wrote:
 Why does this line of code not work for the radio button?

 if ($(this).attr(type) == radio) alert($(this).checked);

 I get 6 alert boxes (I have 6 Radio Buttons) and the alert says
 undefined every time.  But half of them should be true and half should
 be false.  Am I doing something wrong?

 here are two of the radios:

 input name=recvd_loan type=radio value=1 / Yes
 input name=recvd_loan type=radio value=0 / No

 Thanks!


[jQuery] Re: Simple question about Radio Buttons

2008-09-19 Thread Namlet

Great explanation Josh, thanks!


On Sep 19, 3:46 pm, Josh Nathanson [EMAIL PROTECTED] wrote:
 You could use either this.checked or $(this).attr(checked).

 this refers to the dom node, so if you want to use the attr method on
 this you have to jQuery-ize it.

 this.checked would be more performant, since you are not executing the
 jQuery function in that case.

 -- Josh

 - Original Message -
 From: Namlet [EMAIL PROTECTED]
 To: jQuery (English) jquery-en@googlegroups.com
 Sent: Friday, September 19, 2008 1:11 PM
 Subject: [jQuery] Re: Simple question about Radio Buttons

 Well I fixed it, I had to use:

 $(this).attr(checked)

 to get the value.  Should I have known this?

 On Sep 19, 2:48 pm, Namlet [EMAIL PROTECTED] wrote:
  Why does this line of code not work for the radio button?

  if ($(this).attr(type) == radio) alert($(this).checked);

  I get 6 alert boxes (I have 6 Radio Buttons) and the alert says
  undefined every time. But half of them should be true and half should
  be false. Am I doing something wrong?

  here are two of the radios:

  input name=recvd_loan type=radio value=1 / Yes
  input name=recvd_loan type=radio value=0 / No

  Thanks!


[jQuery] Re: borders work fine with all browsers except IE7

2008-09-17 Thread Namlet

Ok, point taken, but I have a CSS file, a JS file, and an XHTML files,
each are about 300 lines.  That's a little too much for this textbox,
so how can I post this info for you to see?  It's not a public
website.  Is there some online service that hosts text displaying
versions of this stuff?



On Sep 16, 1:53 pm, ricardobeat [EMAIL PROTECTED] wrote:
 Impossible to help without seeing some code. I don't see any magical
 jQuery gurus around.

 On Sep 16, 12:01 pm, Namlet [EMAIL PROTECTED] wrote:

  I have a site with several borders that are part of jQuery commands.
  One has rounded corners, others don't.  IE7 doesn't render ANY of
  these borders.  There are two divs that are not touched by jQuery, and
  their borders work fine.  Everything that has a jQuery click event, or
  rounded corners has no border at all.  Any ideas?


[jQuery] Re: How to serialize an Object to JSON String without making it POST like?

2008-09-17 Thread Namlet

So I need to write my own JSON serializer or is there something
already available?

If I do need to write my own, how can I contribute it back to the
community?

Thanks!

On Sep 16, 4:28 pm, Mike Alsup [EMAIL PROTECTED] wrote:
  When I use this function to create a JSON object:

  var formObject = $(:input).serialize();

  and I print it, I get name=valuename=value...  This isn't proper
  JSON string and the .NET webservice I'm sending it to barfs.

  How can I make it stay in the proper format, i.e.

  {'fname':'dave', 'lname':'ward'}

  Thanks!

 jQuery's serialize method does not create JSON strings.  It creates
 URL-encoded strings, as you discovered.


[jQuery] borders work fine with all browsers except IE7

2008-09-16 Thread Namlet

I have a site with several borders that are part of jQuery commands.
One has rounded corners, others don't.  IE7 doesn't render ANY of
these borders.  There are two divs that are not touched by jQuery, and
their borders work fine.  Everything that has a jQuery click event, or
rounded corners has no border at all.  Any ideas?



[jQuery] Trying to use serializeArray to send JSON to a .NET 2.0 Web Service

2008-09-16 Thread Namlet

I am using serializeArray to send a form as a JSON object to a .NET
2.0 Web Service in C#.

I am getting this error, prefix is the first field:

responseText: {Message:Invalid JSON primitive:
prefix.,StackTrace: at
System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()
\r\n at
System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32
depth)\r\n at
System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String
input, Int32 depthLimit, JavaScriptSerializer serializer)\r\n at
System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer
serializer, String input, Type type, Int32 depthLimit)\r\n at
System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T]
(String input)\r\n at
System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext
context, JavaScriptSerializer serializer)\r\n at
System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData
methodData, HttpContext context)\r\n at
System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext
context, WebServiceMethodData
methodData),ExceptionType:System.ArgumentException}

The Web Method is doing nothing right now, just returning the input:
[WebMethod]
public string setBMBJSONString(string guid)
{

return guid;
}

Any idea what's wrong?  Can this be done this way?  Is there a way I
can serialize it to a JSON formatted string instead?

Thanks.



[jQuery] How to serialize an Object to JSON String without making it POST like?

2008-09-16 Thread Namlet

When I use this function to create a JSON object:

var formObject = $(:input).serialize();

and I print it, I get name=valuename=value...  This isn't proper
JSON string and the .NET webservice I'm sending it to barfs.

How can I make it stay in the proper format, i.e.

{'fname':'dave', 'lname':'ward'}

Thanks!


[jQuery] Re: $.ajax isn't parsing JSON object properly

2008-09-12 Thread Namlet

Says undefined, so it's not accessing the properties properly with an
rdata.guid for instance.

Turns out, I need to eval the string which I couldn't get right at
first.  I tried eval(rdata); but it failed.

However, when I tried eval('(' + rdata + ')') it worked fine!  So why
is this how I have to eval it?  It would help me to understand how to
use it.

Thanks!


On Sep 12, 12:59 pm, MorningZ [EMAIL PROTECTED] wrote:
 I cannot access any properties of the object

 Do you get an error?
 Not sure how to access the values?
 Something else?

 The first result is valid JSON (to see, just paste it into the
 excellent JSON Viewer you can download athttp://www.codeplex.com/JsonViewer)

 But you don't provide enough information on what's wrong, so it's
 difficult to tell you what's right


[jQuery] .unbind hover doesn't work

2008-09-05 Thread Namlet

To unbind the above example use:
$(#nav1).unbind('mouseenter mouseleave');

This is what the documentation says, but it doesn't remove the hover
event.  Do I have to do something else?

Thanks.