[jQuery] Re: $.ajax call doesn't complete on 400 bad request response
I see now I misunderstood the complete functionality of "JSONP", no XMLHttpRequest is made at all, and as a result it's not possible to control HTTP headers. In my case a script like: http://localhost:9998/search/jonas? callback=jsonp1263842210822 "> is injected and and loaded by the browser. Is there a way to check whether this is loaded at all? I guess the browser will not evaluate it if the server returns an error-code. As far as I can see an $.ajax( call which uses JSONP functionality will never call the error function. This would mean that the option to use would be to implement custom error handling at the service with messages and HTTP status code 200. -- Anton On Jan 18, 8:26 pm, anton wrote: > A type, sorry, everything works fine without javascript warnings or > errors, can seem to get any function to be called after a request > which return 400. > > Just fixed the server so that it returns correct MIME-type > "application/javascript" instead of just text for errors, this wasn't > the problem though... > > $.ajax({ > url: "http://localhost:9998/search/"; + searchVal + "? > callback=?", > type: "GET", > dataType: "json", > success: function() { > alert("success"); > }, > error: function() { > alert("error"); > }, > complete: function() { > alert("complete"); > } > }); > > Some Firebug info after a call: > === > GEThttp://localhost:9998/search/jonas?callback=jsonp1263842210822400 > Bad Request localhost:9998 > Response Headers: > Server grizzly/1.9.9 > Content-Type application/javascript > Transfer-Encoding chunked > Date Mon, 18 Jan 2010 19:17:15 GMT > Connection close > > Response = jsonp1263842210822({"msg":"[LDAP: error code 4 - Sizelimit > Exceeded]"}) > > > I also find it strange that request is made with Accept Header = */* > instead of "application/json" which is stated as dataType but should > maybe be discussed in another topic... > > have tried using dataType : "jsonp" and skipped the callback info in > url, this gives the exact same result though. > > On Jan 18, 7:09 pm, Nathan Klatt wrote: > > > On Mon, Jan 18, 2010 at 11:05 AM, anton wrote: > > > Can't seem to get any response from an ajax call which response is 400 > > > Bad Request > > > > $.ajax({ > > > url: url > > > type: "GET", > > > Hey, is that missing comma after url a typo? > > > Nathan
[jQuery] Re: $.ajax call doesn't complete on 400 bad request response
A type, sorry, everything works fine without javascript warnings or errors, can seem to get any function to be called after a request which return 400. Just fixed the server so that it returns correct MIME-type "application/javascript" instead of just text for errors, this wasn't the problem though... $.ajax({ url: "http://localhost:9998/search/"; + searchVal + "? callback=?", type: "GET", dataType: "json", success: function() { alert("success"); }, error: function() { alert("error"); }, complete: function() { alert("complete"); } }); Some Firebug info after a call: === GET http://localhost:9998/search/jonas?callback=jsonp1263842210822 400 Bad Request localhost:9998 Response Headers: Server grizzly/1.9.9 Content-Typeapplication/javascript Transfer-Encoding chunked DateMon, 18 Jan 2010 19:17:15 GMT Connection close Response = jsonp1263842210822({"msg":"[LDAP: error code 4 - Sizelimit Exceeded]"}) I also find it strange that request is made with Accept Header = */* instead of "application/json" which is stated as dataType but should maybe be discussed in another topic... have tried using dataType : "jsonp" and skipped the callback info in url, this gives the exact same result though. On Jan 18, 7:09 pm, Nathan Klatt wrote: > On Mon, Jan 18, 2010 at 11:05 AM, anton wrote: > > Can't seem to get any response from an ajax call which response is 400 > > Bad Request > > > $.ajax({ > > url: url > > type: "GET", > > Hey, is that missing comma after url a typo? > > Nathan
[jQuery] Re: $.ajax call doesn't complete on 400 bad request response
success function is not called at all when I receiver error code 400: success: function() { alert("success"); }, error: function() { alert("error"); }, complete: function() { alert("complete"); } None of those are called, and I don't get javascript errors in console... On Jan 18, 6:23 pm, Nathan Klatt wrote: > On Mon, Jan 18, 2010 at 11:05 AM, anton wrote: > > Can't seem to get any response from an ajax call which response is 400 > > Bad Request > > > $.ajax({ > > url: url > > type: "GET", > > dataType: "json", > > success: aj.dataLoaded, > > error: function() { > > alert("error"); > > }, > > complete: function() { > > alert("complete"); > > } > > }); > > > When server responds with error code 400 neither the error function > > nor the complete function is called, any tips on how to correct this? > > What is aj.dataLoaded doing? I believe a 400 will go to the success > callback; after that finishes (assuming it does so :) it should call > the complete callback. Can the call to complete be disabled by > returning false from the success/error callback? > > Nathan
[jQuery] Re: Ajax forms help
Hmm, that's weird... i don't know why escaping/unescaping is an issue... this is an actual working example of returned JSON from what I am working on today: stripped down a bit for brevity, and since Google Groups will break up the "Data" line, it's really all one line (no line breaks like i added) { "HasError":false, "Mode":"Cache_List", "Message":"", "Data":" File Name 022308_Post_Attempt.xml " } and i just simply say $("#Results").html(response.Data); there's no action directly needed by me to "unescape" the class name of the table On Jan 11, 3:41 pm, "Dave Maharaj :: WidePixels.com" wrote: > Sorry for the number of back to back posts...just making progress somewhat. > > OK! I got it part ways no more html after the JSON. > > {"data":{"title":"","year_rec":{"year":"2010"},"description":"","id":"6186d5 > 5b8f0","profile_id":"4b40eea7-2608-4a3b-9c24-7cb04adcd75b"},"status":true,"h > tml":"this is a good test<\/p>\r\n"} > > Now to display the HTML but without all the <\/p>\r\n > > Dave > > > > From: John Arrowwood [mailto:jarro...@gmail.com] > Sent: January-11-10 4:45 PM > To: jquery-en@googlegroups.com > Subject: Re: [jQuery] Re: Ajax forms help > > Your problem looks like it may be on the back-end. Send the code that > generates the JSON. > > On Mon, Jan 11, 2010 at 11:41 AM, Dave Maharaj :: WidePixels.com > > wrote: > > My response comes back from the server looking like this: (don't > think its > right to begin with) > > {"data":{"title":"","year_rec":{"year":"2010"},"description":"","id":"0936d6 > > 115e4","profile_id":"4b40eea7-2608-4a3b-9c24-7cb04adcd75b"},"status":true,"h > tml":"this is a good test<\/p>\r\n"}this is a good test > > But how would I display only the html section and clean it so its > not all > slashed and escaped? > > Thanks > > Dave > > -Original Message- > From: MorningZ [mailto:morni...@gmail.com] > Sent: January-11-10 11:44 AM > To: jQuery (English) > Subject: [jQuery] Re: Ajax forms help > > "But if I am returning json I cant return my normal html" > > I don't understand why... > > I pretty much exclusively use JSON back and forth in my jQuery AJAX > calls > and have a standard JSON object i return: > > { > HasError: , > Message: . > Data: , > Count: > } > > Many times i'll return HTML on the data property there i think > the > problem you are having is how you are creating the JSON return > string, maybe > that's not the right way to do it in PHP ?? (to note, i'm a .NET > guy, i > don't know what the PHP way is) > > On Jan 11, 10:06 am, "Dave Maharaj :: WidePixels.com" > wrote: > > Right on...looks easy enough. > > > Is response.html saying to display it as html? I tried making an > array > > to pass as json from php then json_encode it so my arrr was > $response > > = array('status' => true , 'view' => 'all my html code went here') > > > But when I returned my view data from the array it was all slahsed > > "// /" / / like that. > > > -Original Message- > > From: Ibatex [mailto:mjgris...@gmail.com] > > Sent: January-11-10 4:35 AM > > To: jQuery (English) > > Subject: [jQuery] Re: Ajax forms help > > > The beauty of json is that you can transfer alot of different data > in > > an organized way. You can very easily send back success/failure > status > > along with the html. > > > success: function(response) { > > // Response was a success > > if (response.status) { > > //update my target div > > $('#target_div').html(response.html); > >
RE: [jQuery] Re: Ajax forms help
Sorry for the number of back to back posts...just making progress somewhat. OK! I got it part ways no more html after the JSON. {"data":{"title":"","year_rec":{"year":"2010"},"description":"","id":"6186d5 5b8f0","profile_id":"4b40eea7-2608-4a3b-9c24-7cb04adcd75b"},"status":true,"h tml":"this is a good test<\/p>\r\n"} Now to display the HTML but without all the <\/p>\r\n Dave ________ From: John Arrowwood [mailto:jarro...@gmail.com] Sent: January-11-10 4:45 PM To: jquery-en@googlegroups.com Subject: Re: [jQuery] Re: Ajax forms help Your problem looks like it may be on the back-end. Send the code that generates the JSON. On Mon, Jan 11, 2010 at 11:41 AM, Dave Maharaj :: WidePixels.com wrote: My response comes back from the server looking like this: (don't think its right to begin with) {"data":{"title":"","year_rec":{"year":"2010"},"description":"","id":"0936d6 115e4","profile_id":"4b40eea7-2608-4a3b-9c24-7cb04adcd75b"},"status":true,"h tml":"this is a good test<\/p>\r\n"}this is a good test But how would I display only the html section and clean it so its not all slashed and escaped? Thanks Dave -Original Message- From: MorningZ [mailto:morni...@gmail.com] Sent: January-11-10 11:44 AM To: jQuery (English) Subject: [jQuery] Re: Ajax forms help "But if I am returning json I cant return my normal html" I don't understand why... I pretty much exclusively use JSON back and forth in my jQuery AJAX calls and have a standard JSON object i return: { HasError: , Message: . Data: , Count: } Many times i'll return HTML on the data property there i think the problem you are having is how you are creating the JSON return string, maybe that's not the right way to do it in PHP ?? (to note, i'm a .NET guy, i don't know what the PHP way is) On Jan 11, 10:06 am, "Dave Maharaj :: WidePixels.com" wrote: > Right on...looks easy enough. > > Is response.html saying to display it as html? I tried making an array > to pass as json from php then json_encode it so my arrr was $response > = array('status' => true , 'view' => 'all my html code went here') > > But when I returned my view data from the array it was all slahsed "// /" / / like that. > > -Original Message- > From: Ibatex [mailto:mjgris...@gmail.com] > Sent: January-11-10 4:35 AM > To: jQuery (English) > Subject: [jQuery] Re: Ajax forms help > > The beauty of json is that you can transfer alot of different data in > an organized way. You can very easily send back success/failure status > along with the html. > > success: function(response) { > // Response was a success > if (response.status) { > //update my target div > $('#target_div').html(response.html); > // Response contains errors > } else { > // return the form with the errors > > } > > On Jan 10, 5:00 pm, "Dave Maharaj :: WidePixels.com" > wrote: > > I need some help with a form. > > > I submit the form fine, my problem is depending on the success or > > failure of the form being saved. I will try to explain as simple as > > possible > > > form is in its own div > > > saved data will appear here > > > So what I need is i guess json success true or false response from > > the form being saved or not then in my success > > > success: function(response) { > > // Response was a success > > if (response) { > > //update my target div > >
RE: [jQuery] Re: Ajax forms help
I am using CakePHP to send the JSONfamiliar with that? if ( $this->RequestHandler->isAjax() ) { Configure::write ( 'debug', 0 ); $this->layout = 'ajax'; $this->autoLayout = false; $this->autoRender = false; $this->data['Award']['id'] = $this->Award->generateKey('11'); $this->data['Award']['profile_id'] = $this->Auth->User('id'); $response['data'] = $this->data['Award']; $response['status'] = true; //$response['html'] = $this->render('dummy'); $this->header('Content-Type: application/json'); echo json_encode($response); return; } From: John Arrowwood [mailto:jarro...@gmail.com] Sent: January-11-10 4:45 PM To: jquery-en@googlegroups.com Subject: Re: [jQuery] Re: Ajax forms help Your problem looks like it may be on the back-end. Send the code that generates the JSON. On Mon, Jan 11, 2010 at 11:41 AM, Dave Maharaj :: WidePixels.com wrote: My response comes back from the server looking like this: (don't think its right to begin with) {"data":{"title":"","year_rec":{"year":"2010"},"description":"","id":"0936d6 115e4","profile_id":"4b40eea7-2608-4a3b-9c24-7cb04adcd75b"},"status":true,"h tml":"this is a good test<\/p>\r\n"}this is a good test But how would I display only the html section and clean it so its not all slashed and escaped? Thanks Dave -Original Message- From: MorningZ [mailto:morni...@gmail.com] Sent: January-11-10 11:44 AM To: jQuery (English) Subject: [jQuery] Re: Ajax forms help "But if I am returning json I cant return my normal html" I don't understand why... I pretty much exclusively use JSON back and forth in my jQuery AJAX calls and have a standard JSON object i return: { HasError: , Message: . Data: , Count: } Many times i'll return HTML on the data property there i think the problem you are having is how you are creating the JSON return string, maybe that's not the right way to do it in PHP ?? (to note, i'm a .NET guy, i don't know what the PHP way is) On Jan 11, 10:06 am, "Dave Maharaj :: WidePixels.com" wrote: > Right on...looks easy enough. > > Is response.html saying to display it as html? I tried making an array > to pass as json from php then json_encode it so my arrr was $response > = array('status' => true , 'view' => 'all my html code went here') > > But when I returned my view data from the array it was all slahsed "// /" / / like that. > > -Original Message- > From: Ibatex [mailto:mjgris...@gmail.com] > Sent: January-11-10 4:35 AM > To: jQuery (English) > Subject: [jQuery] Re: Ajax forms help > > The beauty of json is that you can transfer alot of different data in > an organized way. You can very easily send back success/failure status > along with the html. > > success: function(response) { > // Response was a success > if (response.status) { > //update my target div > $('#target_div').html(response.html); > // Response contains errors > } else { > // return the form with the errors > > } > > On Jan 10, 5:00 pm, "Dave Maharaj :: WidePixels.com" > wrote: > > I need some help with a form. > > > I submit the form fine, my problem is depending on the success or > > failure of the form being saved. I will try to explain as simple as > > possible > > > form is in its own div > > > saved data will appear here > > > So what I need is i guess json success true or false response from > > the form being saved or not then in my success > > >
RE: [jQuery] Re: Ajax forms help
Ok so this is my js on the page: $('#test').live('click', test); function test() { var data = $('#add_award').serialize(); $.ajax({ type: "post", url: "/manage/awards/", data: data, dataType: 'json', success: function(response){ alert(response.data.id); } }); } No alert happens. The response shows up as: {"data":{"title":"","year_rec":{"year":"2010"},"description":"","id":"4cec63 725d2","profile_id":"4b40eea7-2608-4a3b-9c24-7cb04adcd75b"},"status":true,"h tml":"this is a good test<\/p>\r\n"}this is a good test Not sure why the html code gets repeated after the json part. I am using cake and so far nobody has been able to assit me so im going on trial and error. So to test out the alert response I removed the html part leaving only data and success so I get a Firebug JSON tab in the response: {"data":{"title":"","year_rec":{"year":"2010"},"description":"","id":"4ff9c8 f01b8","profile_id":"4b40eea7-2608-4a3b-9c24-7cb04adcd75b"},"status":true} And alert(response.data.id); => 4ff9c8f01b8 So its just the darn HTML which is killing me here. Cant figure out how to get just the HTML to apear in the JSON and not display after the code Dave -Original Message- From: Michael Geary [mailto:m...@mg.to] Sent: January-11-10 4:36 PM To: jquery-en@googlegroups.com Subject: Re: [jQuery] Re: Ajax forms help The JSON part of your server response looks fine if you take out the two line breaks - I assume those are just an artifact of posting with Outlook, and your actual JSON response is all on one line. But why does it have the HTML content repeated after the last } that closes the JSON data? You don't want that. Also: > Is response.html saying to display it as html? No! response.html says "take the object named 'response' and give me its property named 'html'." It has nothing to do with displaying anything or specifying its format. Here, let's take your JSON output and paste it into www.jsonlint.com so it's easier to read: { "data": { "title": "", "year_rec": { "year": "2010" }, "description": "", "id": "0936d6115e4", "profile_id": "4b40eea7-2608-4a3b-9c24-7cb04adcd75b" }, "status": true, "html": "this is a good test<\/p>\r\n" } You see, it's an object with three properties, named 'data', 'status', and 'html'. The 'data' property is itself an object with properties of its own. So if you have a variable named 'response' (as in Ibatex's example), then you can get to these various properties like so: response.html (the HTML code) response.data.id (the id) response.data.year_rec.year (the year) What you do with those is then up to you, as in Ibatex's earlier example. BTW do you have the Fiddler debugging proxy server and its JSON plugin (and standalone JSON viewer)? For the work you're doing now, you *need* these. http://www.fiddler2.com/ http://www.fiddler2.com/Fiddler2/extensions.asp -Mike On Mon, Jan 11, 2010 at 11:41 AM, Dave Maharaj :: WidePixels.com wrote: My response comes back from the server looking like this: (don't think its right to begin with) {"data":{"title":"","year_rec":{"year":"2010"},"description":"","id":"0936d6 115e4","profile_id":"4b40eea7-2608-4a3b-9c24-7cb04adcd75b"},"status":true,"h tml":"this is a good test<\/p>\r\n"}this is a good test But how would I display only the html section and clean it so its not all slashed and escaped? Thanks Dave -Original Message- From: MorningZ [mailto:morni...@gmail.com] Sent: January-11-10 11:44 AM To: jQuery (English) Subject: [jQuery] Re: Ajax forms help "But if I am returning json I cant return my normal html" I don't understand why... I pretty much exclusively use JSON back and forth in my jQuery AJAX calls and have a standard JSON object i return: { HasError: , Message: .
RE: [jQuery] Re: Ajax forms help
Very detailed response...thank you. I will give it a try and try an alert on different sections of the response and see what happens. I am using firebug to examine the response. Will check the response and repost and say if it its 1 solid line or broke. Thanks...will post shortly. Dave -Original Message- From: Michael Geary [mailto:m...@mg.to] Sent: January-11-10 4:36 PM To: jquery-en@googlegroups.com Subject: Re: [jQuery] Re: Ajax forms help The JSON part of your server response looks fine if you take out the two line breaks - I assume those are just an artifact of posting with Outlook, and your actual JSON response is all on one line. But why does it have the HTML content repeated after the last } that closes the JSON data? You don't want that. Also: > Is response.html saying to display it as html? No! response.html says "take the object named 'response' and give me its property named 'html'." It has nothing to do with displaying anything or specifying its format. Here, let's take your JSON output and paste it into www.jsonlint.com so it's easier to read: { "data": { "title": "", "year_rec": { "year": "2010" }, "description": "", "id": "0936d6115e4", "profile_id": "4b40eea7-2608-4a3b-9c24-7cb04adcd75b" }, "status": true, "html": "this is a good test<\/p>\r\n" } You see, it's an object with three properties, named 'data', 'status', and 'html'. The 'data' property is itself an object with properties of its own. So if you have a variable named 'response' (as in Ibatex's example), then you can get to these various properties like so: response.html (the HTML code) response.data.id (the id) response.data.year_rec.year (the year) What you do with those is then up to you, as in Ibatex's earlier example. BTW do you have the Fiddler debugging proxy server and its JSON plugin (and standalone JSON viewer)? For the work you're doing now, you *need* these. http://www.fiddler2.com/ http://www.fiddler2.com/Fiddler2/extensions.asp -Mike On Mon, Jan 11, 2010 at 11:41 AM, Dave Maharaj :: WidePixels.com wrote: My response comes back from the server looking like this: (don't think its right to begin with) {"data":{"title":"","year_rec":{"year":"2010"},"description":"","id":"0936d6 115e4","profile_id":"4b40eea7-2608-4a3b-9c24-7cb04adcd75b"},"status":true,"h tml":"this is a good test<\/p>\r\n"}this is a good test But how would I display only the html section and clean it so its not all slashed and escaped? Thanks Dave -Original Message- From: MorningZ [mailto:morni...@gmail.com] Sent: January-11-10 11:44 AM To: jQuery (English) Subject: [jQuery] Re: Ajax forms help "But if I am returning json I cant return my normal html" I don't understand why... I pretty much exclusively use JSON back and forth in my jQuery AJAX calls and have a standard JSON object i return: { HasError: , Message: . Data: , Count: } Many times i'll return HTML on the data property there i think the problem you are having is how you are creating the JSON return string, maybe that's not the right way to do it in PHP ?? (to note, i'm a .NET guy, i don't know what the PHP way is) On Jan 11, 10:06 am, "Dave Maharaj :: WidePixels.com" wrote: > Right on...looks easy enough. > > Is response.html saying to display it as html? I tried making an array > to pass as json from php then json_encode it so my arrr was $response > = array('status' => true , 'view' => 'all my html code went here') > > But when I returned my view data from the array it was all slahsed "// /" / / like that. > > -Original Message- > From: Ibatex [mailto:mjgris...@gmail.com] > Sent: January-11-10 4:35 AM > To: jQuery (English) > Subject: [jQuery] Re: Ajax forms help > > The beauty of json is that you can transfer alot of different data in > an organized way. You can very easily send back success/failure status > along
Re: [jQuery] Re: Ajax forms help
Your problem looks like it may be on the back-end. Send the code that generates the JSON. On Mon, Jan 11, 2010 at 11:41 AM, Dave Maharaj :: WidePixels.com < d...@widepixels.com> wrote: > My response comes back from the server looking like this: (don’t think its > right to begin with) > > > {"data":{"title":"","year_rec":{"year":"2010"},"description":"","id":"0936d6 > > 115e4","profile_id":"4b40eea7-2608-4a3b-9c24-7cb04adcd75b"},"status":true,"h > tml":"this is a good test<\/p>\r\n"}this is a good test > > But how would I display only the html section and clean it so its not all > slashed and escaped? > > Thanks > > Dave > -Original Message- > From: MorningZ [mailto:morni...@gmail.com] > Sent: January-11-10 11:44 AM > To: jQuery (English) > Subject: [jQuery] Re: Ajax forms help > > "But if I am returning json I cant return my normal html" > > I don't understand why... > > I pretty much exclusively use JSON back and forth in my jQuery AJAX calls > and have a standard JSON object i return: > > { > HasError: , > Message: . > Data: , > Count: > } > > Many times i'll return HTML on the data property there i think the > problem you are having is how you are creating the JSON return string, > maybe > that's not the right way to do it in PHP ?? (to note, i'm a .NET guy, i > don't know what the PHP way is) > > On Jan 11, 10:06 am, "Dave Maharaj :: WidePixels.com" > wrote: > > Right on...looks easy enough. > > > > Is response.html saying to display it as html? I tried making an array > > to pass as json from php then json_encode it so my arrr was $response > > = array('status' => true , 'view' => 'all my html code went here') > > > > But when I returned my view data from the array it was all slahsed > "// /" / / like that. > > > > -Original Message- > > From: Ibatex [mailto:mjgris...@gmail.com] > > Sent: January-11-10 4:35 AM > > To: jQuery (English) > > Subject: [jQuery] Re: Ajax forms help > > > > The beauty of json is that you can transfer alot of different data in > > an organized way. You can very easily send back success/failure status > > along with the html. > > > > success: function(response) { > > // Response was a success > > if (response.status) { > > //update my target div > > $('#target_div').html(response.html); > > // Response contains errors > > } else { > > // return the form with the errors > > > > } > > > > On Jan 10, 5:00 pm, "Dave Maharaj :: WidePixels.com" > > wrote: > > > I need some help with a form. > > > > > I submit the form fine, my problem is depending on the success or > > > failure of the form being saved. I will try to explain as simple as > > > possible > > > > > form is in its own div > > > > > saved data will appear here > > > > > So what I need is i guess json success true or false response from > > > the form being saved or not then in my success > > > > > success: function(response) { > > > // Response was a success > > > if (response) { > > > //update my target div > > > // Response contains errors > > > } else { > > > // return the form with the errors > > > > > } > > > > > But if I am returning json I cant return my normal html after the > > > successful save, and if I return my response as html there is no way > > > to tell the js what to do. > > > The form or the target is html code > > > > > How can I tell what the response was (true or false) and return the > > > appropriate html code for the appropriate form or target? > > > > > Thanks > > > > > Dave > > No virus found in this incoming message. > > Checked by AVG -www.avg.com > > Version: 9.0.725 / Virus Database: 270.14.130/2607 - Release Date: > > 01/10/10 16:05:00 > No virus found in this incoming message. > Checked by AVG - www.avg.com > Version: 9.0.725 / Virus Database: 270.14.130/2607 - Release Date: 01/11/10 > 04:05:00 > > -- John Arrowwood John (at) Irie (dash) Inc (dot) com John (at) Arrowwood Photography (dot) com John (at) Hanlons Razor (dot) com -- http://www.irie-inc.com/ http://arrowwood.blogspot.com/
Re: [jQuery] Re: Ajax forms help
The JSON part of your server response looks fine if you take out the two line breaks - I assume those are just an artifact of posting with Outlook, and your actual JSON response is all on one line. But why does it have the HTML content repeated after the last } that closes the JSON data? You don't want that. Also: > Is response.html saying to display it as html? No! response.html says "take the object named 'response' and give me its property named 'html'." It has nothing to do with displaying anything or specifying its format. Here, let's take your JSON output and paste it into www.jsonlint.com so it's easier to read: { "data": { "title": "", "year_rec": { "year": "2010" }, "description": "", "id": "0936d6115e4", "profile_id": "4b40eea7-2608-4a3b-9c24-7cb04adcd75b" }, "status": true, "html": "this is a good test<\/p>\r\n" } You see, it's an object with three properties, named 'data', 'status', and 'html'. The 'data' property is itself an object with properties of its own. So if you have a variable named 'response' (as in Ibatex's example), then you can get to these various properties like so: response.html (the HTML code) response.data.id (the id) response.data.year_rec.year (the year) What you do with those is then up to you, as in Ibatex's earlier example. BTW do you have the Fiddler debugging proxy server and its JSON plugin (and standalone JSON viewer)? For the work you're doing now, you *need* these. http://www.fiddler2.com/ http://www.fiddler2.com/Fiddler2/extensions.asp -Mike On Mon, Jan 11, 2010 at 11:41 AM, Dave Maharaj :: WidePixels.com < d...@widepixels.com> wrote: > My response comes back from the server looking like this: (don’t think its > right to begin with) > > > {"data":{"title":"","year_rec":{"year":"2010"},"description":"","id":"0936d6 > > 115e4","profile_id":"4b40eea7-2608-4a3b-9c24-7cb04adcd75b"},"status":true,"h > tml":"this is a good test<\/p>\r\n"}this is a good test > > But how would I display only the html section and clean it so its not all > slashed and escaped? > > Thanks > > Dave > -Original Message- > From: MorningZ [mailto:morni...@gmail.com] > Sent: January-11-10 11:44 AM > To: jQuery (English) > Subject: [jQuery] Re: Ajax forms help > > "But if I am returning json I cant return my normal html" > > I don't understand why... > > I pretty much exclusively use JSON back and forth in my jQuery AJAX calls > and have a standard JSON object i return: > > { > HasError: , > Message: . > Data: , > Count: > } > > Many times i'll return HTML on the data property there i think the > problem you are having is how you are creating the JSON return string, > maybe > that's not the right way to do it in PHP ?? (to note, i'm a .NET guy, i > don't know what the PHP way is) > > On Jan 11, 10:06 am, "Dave Maharaj :: WidePixels.com" > wrote: > > Right on...looks easy enough. > > > > Is response.html saying to display it as html? I tried making an array > > to pass as json from php then json_encode it so my arrr was $response > > = array('status' => true , 'view' => 'all my html code went here') > > > > But when I returned my view data from the array it was all slahsed > "// /" / / like that. > > > > -Original Message- > > From: Ibatex [mailto:mjgris...@gmail.com] > > Sent: January-11-10 4:35 AM > > To: jQuery (English) > > Subject: [jQuery] Re: Ajax forms help > > > > The beauty of json is that you can transfer alot of different data in > > an organized way. You can very easily send back success/failure status > > along with the html. > > > > success: function(response) { > > // Response was a success > > if (response.status) { > > //update my target div > > $('#target_div').html(response.html); > > // Response contains errors > > } else { > > // return the form with the errors > > > > } > > &g
[jQuery] Re: Ajax forms help
My response comes back from the server looking like this: (dont think its right to begin with) {"data":{"title":"","year_rec":{"year":"2010"},"description":"","id":"0936d6 115e4","profile_id":"4b40eea7-2608-4a3b-9c24-7cb04adcd75b"},"status":true,"h tml":"this is a good test<\/p>\r\n"}this is a good test But how would I display only the html section and clean it so its not all slashed and escaped? Thanks Dave -Original Message- From: MorningZ [mailto:morni...@gmail.com] Sent: January-11-10 11:44 AM To: jQuery (English) Subject: [jQuery] Re: Ajax forms help "But if I am returning json I cant return my normal html" I don't understand why... I pretty much exclusively use JSON back and forth in my jQuery AJAX calls and have a standard JSON object i return: { HasError: , Message: . Data: , Count: } Many times i'll return HTML on the data property there i think the problem you are having is how you are creating the JSON return string, maybe that's not the right way to do it in PHP ?? (to note, i'm a .NET guy, i don't know what the PHP way is) On Jan 11, 10:06 am, "Dave Maharaj :: WidePixels.com" wrote: > Right on...looks easy enough. > > Is response.html saying to display it as html? I tried making an array > to pass as json from php then json_encode it so my arrr was $response > = array('status' => true , 'view' => 'all my html code went here') > > But when I returned my view data from the array it was all slahsed "// /" / / like that. > > -Original Message- > From: Ibatex [mailto:mjgris...@gmail.com] > Sent: January-11-10 4:35 AM > To: jQuery (English) > Subject: [jQuery] Re: Ajax forms help > > The beauty of json is that you can transfer alot of different data in > an organized way. You can very easily send back success/failure status > along with the html. > > success: function(response) { > // Response was a success > if (response.status) { > //update my target div > $('#target_div').html(response.html); > // Response contains errors > } else { > // return the form with the errors > > } > > On Jan 10, 5:00 pm, "Dave Maharaj :: WidePixels.com" > wrote: > > I need some help with a form. > > > I submit the form fine, my problem is depending on the success or > > failure of the form being saved. I will try to explain as simple as > > possible > > > form is in its own div > > > saved data will appear here > > > So what I need is i guess json success true or false response from > > the form being saved or not then in my success > > > success: function(response) { > > // Response was a success > > if (response) { > > //update my target div > > // Response contains errors > > } else { > > // return the form with the errors > > > } > > > But if I am returning json I cant return my normal html after the > > successful save, and if I return my response as html there is no way > > to tell the js what to do. > > The form or the target is html code > > > How can I tell what the response was (true or false) and return the > > appropriate html code for the appropriate form or target? > > > Thanks > > > Dave > No virus found in this incoming message. > Checked by AVG -www.avg.com > Version: 9.0.725 / Virus Database: 270.14.130/2607 - Release Date: > 01/10/10 16:05:00 No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.725 / Virus Database: 270.14.130/2607 - Release Date: 01/11/10 04:05:00
[jQuery] Re: Ajax forms help
"But if I am returning json I cant return my normal html" I don't understand why... I pretty much exclusively use JSON back and forth in my jQuery AJAX calls and have a standard JSON object i return: { HasError: , Message: . Data: , Count: } Many times i'll return HTML on the data property there i think the problem you are having is how you are creating the JSON return string, maybe that's not the right way to do it in PHP ?? (to note, i'm a .NET guy, i don't know what the PHP way is) On Jan 11, 10:06 am, "Dave Maharaj :: WidePixels.com" wrote: > Right on...looks easy enough. > > Is response.html saying to display it as html? I tried making an array to > pass as json from php then json_encode it so my arrr was $response = > array('status' => true , 'view' => 'all my html code went here') > > But when I returned my view data from the array it was all slahsed /" / / like that. > > -Original Message----- > From: Ibatex [mailto:mjgris...@gmail.com] > Sent: January-11-10 4:35 AM > To: jQuery (English) > Subject: [jQuery] Re: Ajax forms help > > The beauty of json is that you can transfer alot of different data in an > organized way. You can very easily send back success/failure status along > with the html. > > success: function(response) { > // Response was a success > if (response.status) { > //update my target div > $('#target_div').html(response.html); > // Response contains errors > } else { > // return the form with the errors > > } > > On Jan 10, 5:00 pm, "Dave Maharaj :: WidePixels.com" > wrote: > > I need some help with a form. > > > I submit the form fine, my problem is depending on the success or > > failure of the form being saved. I will try to explain as simple as > > possible > > > form is in its own div > > > saved data will appear here > > > So what I need is i guess json success true or false response from the > > form being saved or not then in my success > > > success: function(response) { > > // Response was a success > > if (response) { > > //update my target div > > // Response contains errors > > } else { > > // return the form with the errors > > > } > > > But if I am returning json I cant return my normal html after the > > successful save, and if I return my response as html there is no way > > to tell the js what to do. > > The form or the target is html code > > > How can I tell what the response was (true or false) and return the > > appropriate html code for the appropriate form or target? > > > Thanks > > > Dave > No virus found in this incoming message. > Checked by AVG -www.avg.com > Version: 9.0.725 / Virus Database: 270.14.130/2607 - Release Date: 01/10/10 > 16:05:00
RE: [jQuery] Re: Ajax forms help
Right on...looks easy enough. Is response.html saying to display it as html? I tried making an array to pass as json from php then json_encode it so my arrr was $response = array('status' => true , 'view' => 'all my html code went here') But when I returned my view data from the array it was all slahsed mailto:mjgris...@gmail.com] Sent: January-11-10 4:35 AM To: jQuery (English) Subject: [jQuery] Re: Ajax forms help The beauty of json is that you can transfer alot of different data in an organized way. You can very easily send back success/failure status along with the html. success: function(response) { // Response was a success if (response.status) { //update my target div $('#target_div').html(response.html); // Response contains errors } else { // return the form with the errors } On Jan 10, 5:00 pm, "Dave Maharaj :: WidePixels.com" wrote: > I need some help with a form. > > I submit the form fine, my problem is depending on the success or > failure of the form being saved. I will try to explain as simple as > possible > > form is in its own div > > saved data will appear here > > So what I need is i guess json success true or false response from the > form being saved or not then in my success > > success: function(response) { > // Response was a success > if (response) { > //update my target div > // Response contains errors > } else { > // return the form with the errors > > } > > But if I am returning json I cant return my normal html after the > successful save, and if I return my response as html there is no way > to tell the js what to do. > The form or the target is html code > > How can I tell what the response was (true or false) and return the > appropriate html code for the appropriate form or target? > > Thanks > > Dave No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.725 / Virus Database: 270.14.130/2607 - Release Date: 01/10/10 16:05:00
[jQuery] Re: Ajax forms help
The beauty of json is that you can transfer alot of different data in an organized way. You can very easily send back success/failure status along with the html. success: function(response) { // Response was a success if (response.status) { //update my target div $('#target_div').html(response.html); // Response contains errors } else { // return the form with the errors } On Jan 10, 5:00 pm, "Dave Maharaj :: WidePixels.com" wrote: > I need some help with a form. > > I submit the form fine, my problem is depending on the success or failure of > the form being saved. I will try to explain as simple as possible > > form is in its own div > > saved data will appear here > > So what I need is i guess json success true or false response from the form > being saved or not then in my success > > success: function(response) { > // Response was a success > if (response) { > //update my target div > // Response contains errors > } else { > // return the form with the errors > > } > > But if I am returning json I cant return my normal html after the successful > save, and if I return my response as html there is no way to tell the js > what to do. > The form or the target is html code > > How can I tell what the response was (true or false) and return the > appropriate html code for the appropriate form or target? > > Thanks > > Dave
Re: [jQuery] Re: ajax image
So, why can't you just create a new node with a src attribute? It will automatically download the image in the background, much like with AJAX. Is the problem that you want to ensure that the image is fully downloaded before you try to display it? Have you tried $(imgTag).ready(...)? (Don't know if that works or not, never tried it) On Wed, Jan 6, 2010 at 8:14 AM, Mean Mike wrote: > > > So you are trying to use jQuery's ".load()" functionality with an > > actual image (i assume that your php sets the content type to > image/ > > jpeg, image/gif, etc and writes out the actual binary image > data) ? > > YES ! that is correct. > > > that's not going to work, as the ".load()" loads the result of the > > Ajax call into the innerHtml of DOM object > > I'm assuming thats why I get Array > > > I don't know though, you're talking "same function" but have > posted > > about three different functions so far, $.ajax, .load, and your > custom > > function > mmm sorry for the confusion > > I wanted to see if i could just get it to work with load that's why I > mentioned it .. > > > but bottom line is, the $.ajax call which ultimately > > gets called wouldn't be a replacement for , > > bummer 8 ^ ( > > > *unless* you wanted to use data url vales as image sources > (like:http://www.websiteoptimization.com/speed/tweak/inline-images/), > but > > the problem with that, like almost all cool ideas like that link > > shows, is it doesn't work with IE > > neat concept but not doable trying to stick with ajax > > Thanks for your help > Mean Mike > -- John Arrowwood John (at) Irie (dash) Inc (dot) com John (at) Arrowwood Photography (dot) com John (at) Hanlons Razor (dot) com -- http://www.irie-inc.com/ http://arrowwood.blogspot.com/
[jQuery] Re: ajax image
> So you are trying to use jQuery's ".load()" functionality with an > actual image (i assume that your php sets the content type to image/ > jpeg, image/gif, etc and writes out the actual binary image data) ? YES ! that is correct. > that's not going to work, as the ".load()" loads the result of the > Ajax call into the innerHtml of DOM object I'm assuming thats why I get Array > I don't know though, you're talking "same function" but have posted > about three different functions so far, $.ajax, .load, and your custom > function mmm sorry for the confusion I wanted to see if i could just get it to work with load that's why I mentioned it .. > but bottom line is, the $.ajax call which ultimately > gets called wouldn't be a replacement for , bummer 8 ^ ( > *unless* you wanted to use data url vales as image sources (like:http://www.websiteoptimization.com/speed/tweak/inline-images/), but > the problem with that, like almost all cool ideas like that link > shows, is it doesn't work with IE neat concept but not doable trying to stick with ajax Thanks for your help Mean Mike
[jQuery] Re: ajax image
So you are trying to use jQuery's ".load()" functionality with an actual image (i assume that your php sets the content type to image/ jpeg, image/gif, etc and writes out the actual binary image data) ? that's not going to work, as the ".load()" loads the result of the Ajax call into the innerHtml of DOM object I don't know though, you're talking "same function" but have posted about three different functions so far, $.ajax, .load, and your custom function but bottom line is, the $.ajax call which ultimately gets called wouldn't be a replacement for , *unless* you wanted to use data url vales as image sources (like: http://www.websiteoptimization.com/speed/tweak/inline-images/), but the problem with that, like almost all cool ideas like that link shows, is it doesn't work with IE On Jan 6, 10:48 am, Mean Mike wrote: > basically all ajax calls go through > > $.ajax({.}); > > I made a function that gets passed all the parameters that I want in > the ajax call > > oddly enough i can't get load to work right either i just get Array > returned > > On Jan 6, 10:33 am, MorningZ wrote: > > > > I want all my ajax calls to run through the same ajax function > > > What "same" ajax function? > > > On Jan 6, 10:29 am, Mean Mike wrote: > > > > ok so I figured out that you can put in image in your page using .load > > > (imageloader.php) but is there a way to load an image using regular > > > ajax call . > > > > alittle more explanation of what I'm trying to do > > > > in my php I use imagejpeg function which outputs the image using gd > > > great! > > > > and in my html i use to just go and that worked except now I don't > > > want to pass that info in the query string I want to post the info AND > > > I want all my ajax calls to run through the same ajax function which > > > is why I don't want to use .load > > > > any thoughts or suggestions > > > > mean mike
[jQuery] Re: ajax image
basically all ajax calls go through $.ajax({.}); I made a function that gets passed all the parameters that I want in the ajax call oddly enough i can't get load to work right either i just get Array returned On Jan 6, 10:33 am, MorningZ wrote: > > I want all my ajax calls to run through the same ajax function > > What "same" ajax function? > > On Jan 6, 10:29 am, Mean Mike wrote: > > > ok so I figured out that you can put in image in your page using .load > > (imageloader.php) but is there a way to load an image using regular > > ajax call . > > > alittle more explanation of what I'm trying to do > > > in my php I use imagejpeg function which outputs the image using gd > > great! > > > and in my html i use to just go and that worked except now I don't > > want to pass that info in the query string I want to post the info AND > > I want all my ajax calls to run through the same ajax function which > > is why I don't want to use .load > > > any thoughts or suggestions > > > mean mike
[jQuery] Re: ajax image
> I want all my ajax calls to run through the same ajax function What "same" ajax function? On Jan 6, 10:29 am, Mean Mike wrote: > ok so I figured out that you can put in image in your page using .load > (imageloader.php) but is there a way to load an image using regular > ajax call . > > alittle more explanation of what I'm trying to do > > in my php I use imagejpeg function which outputs the image using gd > great! > > and in my html i use to just go and that worked except now I don't > want to pass that info in the query string I want to post the info AND > I want all my ajax calls to run through the same ajax function which > is why I don't want to use .load > > any thoughts or suggestions > > mean mike
[jQuery] Re: Ajax error handling & textStatus
What about $.load() callback? Seems like its called in all possible cases. The only disadvantage is error checking - is there any helper in jQuery to check textStatus for error? This one is not particularly beautiful. if (textStatus == 'error' || textStatus == 'timeout' || textStatus == 'parsererror') { ... } -- anatoly t. On Dec 9, 7:13 pm, "T.J. Simmons" wrote: > Are you using $.ajaxor one of the otherAJAXfunctions? $.get and the > rest only execute a callback upon success; you'll need to use $.ajax > if you want a callback for anerror. > > http://docs.jquery.com/Ajax/jQuery.get#urldatacallbacktypehas some > more information on that. > > -T.J. > > On Dec 9, 6:30 am, Cameron van den Bergh > > wrote: > > Good day, > > > When executing anajaxrequest, i've noticed the following problems : > > - the textStatus callback parameter is always set to success ; > > - the callback isn't triggered if a downloaderroroccurs (404 for > > example). > > > I understand that the second problem might be unsolvable but is there > > any way to get the textStatus to work properly or is it still being > > worked on ? > > > Thanks for your help, > > > Cameron
[jQuery] Re: ajax success event does not work
try also catching the "error" event and see what the problem is (which make no doubt about it, something is wrong with the response for jQuery to not go into "success" $.ajax({ type: "POST", url: "submit1.php", data: $("#regist").serialize(), dataType: "json", success: function(){ $("#loading").append("you are here"); }, error: function(x,y,z) { // x.responseText <-- will have the server side error message if PHP outputs what is wrong } }); On Dec 28, 8:20 am, idcoder wrote: > Hi, > Can anyone explain me what does success function arguments > contain..for ajax jquery.. > I read the following in the documentation > > success -> Function > A function to be called if the request succeeds. The function gets > passed two arguments: The data returned from the server, formatted > according to the 'dataType' parameter, and a string describing the > status. This is an Ajax Event. > > function (data, textStatus) { > // data could be xmlDoc, jsonObj, html, text, etc... > this; // the options for this ajax request > > } > > "i want to know what is the data and textStatus" > > I have this code here : > > $(document).ready(function(){ > $("form#regist").submit(function() { > var str = $("#regist").serialize(); > $.ajax({ > type: "POST", > url: "submit1.php", > data: $("#regist").serialize(), > dataType: "json", > success: function(){ > $("#loading").append("you are here"); > } > > }); > return false; > }); > > }); > > the success part does not work.. i can enter the data into the DB if > all fields entered are correct..However if something is wrong then > nothing happens. > > Can anyone guide me where i am going wrong..Thanks a lot..
[jQuery] Re: ajax
Hey thanks for a reply... I corrected the selector as pointed by you..But is still cannot make anything inside success work.. On Dec 17, 5:18 am, Michael Lawson wrote: > Is your selector correct for your success function? > > perhaps you meant $("#loading") instead of $("loading") ? > > cheers > > Michael Lawson > Development Lead, Global Solutions, ibm.com > Phone: 1-276-206-8393 > E-mail: mjlaw...@us.ibm.com > > 'When seen from outer space, our beautiful blue planet has no national > boundaries.' > > http://www.givesmehope.com/ > > From: idcoder > > > To: "jQuery (English)" > > > Date: 12/17/2009 08:15 AM > > > Subject: [jQuery] ajax > > > i am trying to submit a form using jquery and ajax. The form gets > submitted without going to the url through ajax and values are entered > successfully in DB if all entries are correct and validated. also it > does not updated the DB if any errors. > > here is the javascript > > $(document).ready(function(){ > > $('#regist').submit(function(e) { > > $.ajax({ > type: "POST", > url: "submit1.php", > data: $('#regist').serialize(), > dataType: "json", > success: function(){ > $("loading").append(" id='checkmark' src='images/check.png' />"); > > } > }); > return false; > e.preventDefault(); > > }); > > }); > > But i cannot work out the success event in ajax..anything i insert > into success event does not work...any help would be > appreciated..thanks > > graycol.gif > < 1KViewDownload > > ecblank.gif > < 1KViewDownload
[jQuery] Re: Ajax values are lost between 2 operations
it's not the problem, it's working without ajax :D any other guess ? :o i'm stuck with that and i cannot move foward until the problem is fixed ="'( On 27 déc, 23:46, Charlie wrote: > I don't do much with flash but this looks strange to me and is what > is being written into DOM by your getScript > value="data-file=../graphiques/notes.php&loading=Gamer Certified, chargement > des donn?es..."/> > Tristan wrote:if it can help, here's the link > :http://www.gamer-certified.fr/statistiques/par-hebergeur.php1) yeap they are > correct 2) i tryed that but it still not works 3) php is doing his part, > datas are correctly updated with the help of the POST value > $("#nomGSP").change(function () { //get the username var hebergeur1 = > $('#nomGSP').val(); //use ajax to run the check > $.post("/graphiques/notes.php", { hebergeur1: hebergeur1 } , function(data){ > $.getScript("graphique3.js"); },"script"); }); thanks
Re: [jQuery] Re: Ajax values are lost between 2 operations
I don't do much with flash but this looks strange to me and is what is being written into DOM by your getScript Tristan wrote: if it can help, here's the link : http://www.gamer-certified.fr/statistiques/par-hebergeur.php 1) yeap they are correct 2) i tryed that but it still not works 3) php is doing his part, datas are correctly updated with the help of the POST value $("#nomGSP").change(function () { //get the username var hebergeur1 = $('#nomGSP').val(); //use ajax to run the check $.post("/graphiques/notes.php", { hebergeur1: hebergeur1 } , function(data){ $.getScript("graphique3.js"); },"script"); }); thanks
[jQuery] Re: Ajax values are lost between 2 operations
if it can help, here's the link : http://www.gamer-certified.fr/statistiques/par-hebergeur.php 1) yeap they are correct 2) i tryed that but it still not works 3) php is doing his part, datas are correctly updated with the help of the POST value $("#nomGSP").change(function () { //get the username var hebergeur1 = $('#nomGSP').val(); //use ajax to run the check $.post("/graphiques/notes.php", { hebergeur1: hebergeur1 } , function(data){ $.getScript("graphique3.js"); },"script"); }); thanks
[jQuery] Re: Ajax values are lost between 2 operations
thx for the reply 1) yeah, the values are correct i checked that with firebug 2) i tried putting the getScript in callback (i don't know if i did this right) but it's the same no data loaded 3) the php part is doing well i've got the right values in notes.php according to what users select in the FORM and send by $.post i want graphique3.js to reload the chart with my new datas just updated in notes.php ='(( $(document).ready(function(){ $("#nomGSP").change(function () { //get the username var hebergeur1 = $('#nomGSP').val(); //use ajax to run the check $.post("/graphiques/notes.php", { hebergeur1: hebergeur1 } , function(data){ $.getScript("graphique3.js"); },"script"); }); }); On 27 déc, 21:04, Charlie wrote: > lots of possibilities here...a link would help. > 1) are the correct values being sent in post? Firebug can be very helpful for > determining this using the "Show XMLHttpRequests" option. > 2)getScript may be getting called prior to notes.php having finished > processing (AJAX is asynchronous), could try putting the getScript as a > callback to $Post > 3) is the php doing what it is supposed to? withing the callback you could > look a the values it generates also to see what is happening > Tristan wrote:Hi, i've got a little problem and i need your help please : my > script does : 1- post a value in "notes.php" to update values according to > what is send. 2- reload the script which calls an flash chart to update it > the problem is : the datas are correctly updated in /notes.php when calling > again the script to update the chart it's working BUT the values in notes.php > are reset to initial value (which is 0) so the chart is showed empty (because > the charts fils its data with notes.php) $(document).ready(function(){ > $("#nomGSP").change(function () { var hebergeur1 = $('#nomGSP').val(); > $.post("/graphiques/notes.php", { hebergeur1: hebergeur1 } ); > $.getScript("graphique3.js"); }); }); Thanks.
Re: [jQuery] Re: AJAX request
Thanks for your help. Now it works fine. I have also added your idea for checking if it is the same string and I also make the AJAX request only if there are more than 2 chars. The content requested by AJAX prints a combo box and I want to load a certain URL when an element from that combo box is chosen. The problem is that I can't create an event handler to that combo box which doesn't exist when the page is first loaded. Is it possible to create the event handler (onchange), and only after this to create the combo box element using an AJAX request? Or I would need to first create the combo box in the main page, hide it, and add only its content from an AJAX request and then show it? Thanks. Octavian From: "Sime Vidas" I did some testing and didn't experience your problems... give us your code or put a demo online Another thing... you should also check if the input value has changed since the last keyup event, so you don't send the same data if for example the ENTER or SHIFT keys are pressed you can store the input value for every keyup event and than compare it with the value of the previous keyup event like this $("#term").keyup(function() { if (($(this).val().length >= 3) && ($(this).data("currentValue") ! == $(this).val())) { // do AJAX request } $(this).data("currentValue", $(this).val()); return false; }); Also returning false is a nice idea, so that ancestor keyup events don't trigger this handler
[jQuery] Re: AJAX request
I did some testing and didn't experience your problems... give us your code or put a demo online Another thing... you should also check if the input value has changed since the last keyup event, so you don't send the same data if for example the ENTER or SHIFT keys are pressed you can store the input value for every keyup event and than compare it with the value of the previous keyup event like this $("#term").keyup(function() { if (($(this).val().length >= 3) && ($(this).data("currentValue") ! == $(this).val())) { // do AJAX request } $(this).data("currentValue", $(this).val()); return false; }); Also returning false is a nice idea, so that ancestor keyup events don't trigger this handler
[jQuery] Re: $.ajax POST on ff3.5 and Chrome
So, i've figured out why that happens: in case of ff and chrome that is just some security policy, which forbids to do post on "remote host". Solution is quite simple - place controller and hmtl page with your scripts on same host, and after that parameter "url" in $.ajax post will transformed to url: "/api?callback=?&_=?" instead of http://localhost:9090/api...
[jQuery] Re: AJAX and the Content-Type response header
Thanks for your reply, David. > i am afraid you have no way to parse the "Content-Type" in your > javascript. because it the the header of the response, and you can > only get the body (the content) of the response. This is not true. The XMLHttpRequest object has a getResponseHeader function, which you can call like this: xhr.getResponseHeader('Content- Type'). > actually, for a ajax to be able to work correctly, you MUST guarantee > the request you send with ajax can get what you want, and you always > know beforehand what the format (content type) it would be. Not necessarily. After you receive the response, you can still check whether it is an object or a string (i.e. html). By doing so, you can then decide what to do with it. > for jquery, if you do not specify the content type parameter, it is > smart enough to figure out what it is. Could you please elaborate on this? When jquery figures out the content type of the response, what does it use that information for? As far as I can tell, it doesn't eval it, if the content type is 'application/json'. On Dec 18, 12:47 pm, Xi Shen wrote: > i am afraid you have no way to parse the "Content-Type" in your > javascript. because it the the header of the response, and you can > only get the body (the content) of the response. > > actually, for a ajax to be able to work correctly, you MUST guarantee > the request you send with ajax can get what you want, and you always > know beforehand what the format (content type) it would be. > > for jquery, if you do not specify the content type parameter, it is > smart enough to figure out what it is. > > > > On Fri, Dec 18, 2009 at 6:50 AM, MrM wrote: > > Hi, > > > Firstly, let me apologize if this has been discussed before. I have > > searched the group and couldn't find anything on the subject. > > > Now, to my question. Am I correct to assume that the jQuery.ajax > > function pays no heed to the Content-Type response header it receives > > from the server? If so, can I ask why? For instance, if the server > > sends 'application/json', it is fairly safe to assume that the > > response will be in JSON format and should therefore be eval'd. > > > I have a situation where I do not know beforehand, what type of data > > the server will return, and therefore cannot specify a dataType > > parameter. In this case, I would like jQuery to parse the response, if > > it receives a 'Content-Type' header of 'application/json', and only > > then. If the header received is 'text/html', the response should not > > be parsed. > > > Is there a reason why the 'Content-Type' response header is being > > ignored, when the dataType parameter is not specified? Or is this not > > the case and I am missing something? > > > Thanks! > > -- > Best Regards, > David Shen > > http://twitter.com/davidshen84/http://meme.yahoo.com/davidshen84/
[jQuery] Re: AJAX POST listener
Thanks Charlie Unfortunately, while the code managed to trigger on the first load of the page. Subsequent AJAX/POST calls from within the same page wouldn't be triggered. Any way to combine this with a 'live' function? On Dec 11, 9:53 pm, Charlie wrote: > when in doubt the jQuery docs are your best friend > copy/paste straight from Ajax examples:$.ajax({ type: "POST", url: > "some.php", data: "name=John&location=Boston", success: function(msg){ alert( > "Data Saved: " + msg ); } });success callbacks fire when return data is > received, do whatever you need to do within the success > callbackhttp://docs.jquery.com/Ajax/jQuery.ajax#options > Justin wrote:Hi all, I'm trying to implement a way to execute a jquery > function (i created) only when an AJAX POST request has status of complete. > The AJAX itself is out of my reach (controlled by the application) but I want > to be able to listen to the event. If I'm not mistaken, the AJAX in jQuery > mainly uses the GET method? If any one can provide any insight as to how I > can have an event trigger on AJAX POST method that would be fantastic. > Regards, Justin
[jQuery] Re: ajax
Thanks, getScript worked :D, appreciate it!!! Now i got another problem :s i´m using special characters åäö cause its a swedish site, iso 8859-1, and when the script loads it doesnt get properly encoded so i cant see those characers.( Im setting textfields with example text ) Is there a way to encode it? George On 12 Dec, 03:25, Charlie wrote: > page that gets loaded doesn't include head > have you tried $.getScript? or you can insert script in body of page being > loadedhttp://docs.jquery.com/Ajax/jQuery.getScript#urlcallback > Jojje wrote:Hi! I have a question regarding ajax. In my script i have a lot > of css rules set with jquery. And when i use the .load ajax function the page > gets loaded but the css rules from the script doesnt, or the script does not > get loaded, so i have to refresh the page. Is there a way to get the script > loaded as well without putting a link to the script in the page that is to > get loaded? Or is that how you are supposed to do it? Regards George
[jQuery] Re: Ajax error handling & textStatus
No problem, glad to help. -T.J. On Dec 9, 1:12 pm, Cameron van den Bergh wrote: > Thank you for this information, indeed, i was using $.get. > > On 9 déc, 18:13, "T.J. Simmons" wrote: > > > > > Are you using $.ajax or one of the other AJAX functions? $.get and the > > rest only execute a callback upon success; you'll need to use $.ajax > > if you want a callback for an error. > > >http://docs.jquery.com/Ajax/jQuery.get#urldatacallbacktypehassome > > more information on that. > > > -T.J. > > > On Dec 9, 6:30 am, Cameron van den Bergh > > > wrote: > > > Good day, > > > > When executing an ajax request, i've noticed the following problems : > > > - the textStatus callback parameter is always set to success ; > > > - the callback isn't triggered if a download error occurs (404 for > > > example). > > > > I understand that the second problem might be unsolvable but is there > > > any way to get the textStatus to work properly or is it still being > > > worked on ? > > > > Thanks for your help, > > > > Cameron
[jQuery] Re: Ajax error handling & textStatus
Thank you for this information, indeed, i was using $.get. On 9 déc, 18:13, "T.J. Simmons" wrote: > Are you using $.ajax or one of the other AJAX functions? $.get and the > rest only execute a callback upon success; you'll need to use $.ajax > if you want a callback for an error. > > http://docs.jquery.com/Ajax/jQuery.get#urldatacallbacktypehas some > more information on that. > > -T.J. > > On Dec 9, 6:30 am, Cameron van den Bergh > > > > wrote: > > Good day, > > > When executing an ajax request, i've noticed the following problems : > > - the textStatus callback parameter is always set to success ; > > - the callback isn't triggered if a download error occurs (404 for > > example). > > > I understand that the second problem might be unsolvable but is there > > any way to get the textStatus to work properly or is it still being > > worked on ? > > > Thanks for your help, > > > Cameron
[jQuery] Re: Ajax error handling & textStatus
Are you using $.ajax or one of the other AJAX functions? $.get and the rest only execute a callback upon success; you'll need to use $.ajax if you want a callback for an error. http://docs.jquery.com/Ajax/jQuery.get#urldatacallbacktype has some more information on that. -T.J. On Dec 9, 6:30 am, Cameron van den Bergh wrote: > Good day, > > When executing an ajax request, i've noticed the following problems : > - the textStatus callback parameter is always set to success ; > - the callback isn't triggered if a download error occurs (404 for > example). > > I understand that the second problem might be unsolvable but is there > any way to get the textStatus to work properly or is it still being > worked on ? > > Thanks for your help, > > Cameron
[jQuery] Re: Ajax , Json, and error firing instead of success
Dear Mike, I think i'm on something... To be precise, my json is generated through a jsp parsing. So its dynamic, and imports taglibs in first place. These imports generate 'natural' whitespace. So I started hardcoding this jsp/json anwser, stripping away taglib imports. Wich gave me a clean, whitspace free, json answer. And it worked.I suppose whitespace before json content is a problem to IE6/7. Now, rather than trying to reconfigure my jboss server (production reconfiguration is a bit more sensible than local, so I'll forget about it for now...), I'm willing to strip the ajax answer before deciding if success or not...
Re: [jQuery] Re: Ajax , Json, and error firing instead of success
It's probably 'parsererror', not 'parseerror', right? If you search the jQuery source for 'parsererror', you will find the two places where that error can be thrown. That may shed a little light on it. Actually what I would do would be to start stripping down the JSON response until the error goes away. When it starts working (or at least parses OK), then you know the error was in the part you just removed. Your JSON data certainly *looks* OK, and it passes the validator at www.jsonlint.com, but there must be something in it making IE6/7 unhappy. It works OK in IE8, right? -Mike On Tue, Dec 8, 2009 at 11:48 PM, elpatator wrote: > Dear all, > as suggested above, I just made a quick test using > error: function(XMLHttpRequest, textStatus, errorThrown) > { >alert("XMLHttpRequest: " + XMLHttpRequest); > alert("textStatus: " + textStatus); > alert("errorThrown: " + errorThrown); > }, > > Wich, in IE6/7, returns me "textStatus:parseerror". What the hell ? >
[jQuery] Re: Ajax , Json, and error firing instead of success
Dear all, as suggested above, I just made a quick test using error: function(XMLHttpRequest, textStatus, errorThrown) { alert("XMLHttpRequest: " + XMLHttpRequest); alert("textStatus: " + textStatus); alert("errorThrown: " + errorThrown); }, Wich, in IE6/7, returns me "textStatus:parseerror". What the hell ?
Re: [jQuery] Re: Ajax , Json, and error firing instead of success
Yeah, the eval() is undoubtedly wrong, but that wouldn't be the issue here if it's never getting to the success callback. Is there any clue about the error in the arguments passed to the error callback? You have the wrong parameter list in that function. It takes three arguments as shown here: http://docs.jquery.com/Ajax/jQuery.ajax#options error: function( XMLHttpRequest, textStatus, errorThrown ) { // typically only one of textStatus or errorThrown // will have info } -Mike On Tue, Dec 8, 2009 at 12:20 PM, MorningZ wrote: > Is there a reason why you have "eval()" ? jQuery will do that by > itself if you are telling it to retrieve JSON > > > On Dec 8, 1:44 pm, elpatator wrote: > > Hi people, > > I'm trying to make an ajax request, hoping for a clean json response > > to come up. Firefox, as usual, behaves like a charm, but when it comes > > to IE 6 and 7, it's the error function that's fired. > > $.ajax({ > > url: action, > > data: data, > > type: "GET", > > dataType: "json", > > error: function(msg) { > >alert("Error: " + msg); > >alert("URL: " + action); > >alert("DATA: " + data); > > }, > > success: function(reponse) { > > var result = eval("("+reponse+")"); > > alert(result); > > console.info(reponse); > >[... ...] > > > > Using Charles Web DEbbuging Proxy, I started tracing what's happening > > when IE calls for ajax; > > here's what Charles says: > > { > > "totalPanier": "0,00€", > > "articles": [ > > { > > "id": "8a8b8d632481567f01248156fac90009", > > "prixAffiche": "0,00", > > "quantite": "0", > > "libelle": "Carte BEST CADEAUX à montant variable", > > "montantRemise": "", > > "prixTotal": "00,00€" > > }, > > { > > "id": "8a8b8d632481567f0124815706910010", > > "prixAffiche": "80,00", > > "quantite": "0", > > "libelle": "Carte BEST CADEAUX 80 Euros", > > "montantRemise": "", > > "prixTotal": "00,00€" > > }, > > { > > "id": "8a8b8d632481567f012481570578000f", > > "prixAffiche": "50,00", > > "quantite": "0", > > "libelle": "Carte BEST CADEAUX 50 Euros", > > "montantRemise": "", > > "prixTotal": "00,00€" > > }, > > { > > "id": "8a8b8d632481567f012481570549000e", > > "prixAffiche": "30,00", > > "quantite": "0", > > "libelle": "Carte BEST CADEAUX 30 Euros", > > "montantRemise": "", > > "prixTotal": "00,00€" > > }, > > { > > "id": "8a8b8d632481567f012481570364000d", > > "prixAffiche": "15,00", > > "quantite": "0", > > "libelle": "Carte BEST CADEAUX 15 Euros", > > "montantRemise": "", > > "prixTotal": "00,00€" > > } > > ]} > > > > That's ... JSON, perfectlly formated. > > Here's for the headers now: > > HTTP/1.1 200 OK > > Server Apache-Coyote/1.1 > > X-Powered-ByServlet 2.4; JBoss-4.0.3SP1 (build: > > CVSTag=JBoss_4_0_3_SP1 date=200510231054)/Tomcat-5.5 > > Content-Typeapplication/json;charset=UTF-8 > > Content-Length 1221 > > DateTue, 08 Dec 2009 18:41:05 GMT > > > > Woot! What the hell am I missing ? Thanks for the great help you could > > (and I hope, will) provide !!! >
[jQuery] Re: Ajax , Json, and error firing instead of success
Is there a reason why you have "eval()" ? jQuery will do that by itself if you are telling it to retrieve JSON On Dec 8, 1:44 pm, elpatator wrote: > Hi people, > I'm trying to make an ajax request, hoping for a clean json response > to come up. Firefox, as usual, behaves like a charm, but when it comes > to IE 6 and 7, it's the error function that's fired. > $.ajax({ > url: action, > data: data, > type: "GET", > dataType: "json", > error: function(msg) { > alert("Error: " + msg); > alert("URL: " + action); > alert("DATA: " + data); > }, > success: function(reponse) { > var result = eval("("+reponse+")"); > alert(result); > console.info(reponse); > [... ...] > > Using Charles Web DEbbuging Proxy, I started tracing what's happening > when IE calls for ajax; > here's what Charles says: > { > "totalPanier": "0,00€", > "articles": [ > { > "id": "8a8b8d632481567f01248156fac90009", > "prixAffiche": "0,00", > "quantite": "0", > "libelle": "Carte BEST CADEAUX à montant variable", > "montantRemise": "", > "prixTotal": "00,00€" > }, > { > "id": "8a8b8d632481567f0124815706910010", > "prixAffiche": "80,00", > "quantite": "0", > "libelle": "Carte BEST CADEAUX 80 Euros", > "montantRemise": "", > "prixTotal": "00,00€" > }, > { > "id": "8a8b8d632481567f012481570578000f", > "prixAffiche": "50,00", > "quantite": "0", > "libelle": "Carte BEST CADEAUX 50 Euros", > "montantRemise": "", > "prixTotal": "00,00€" > }, > { > "id": "8a8b8d632481567f012481570549000e", > "prixAffiche": "30,00", > "quantite": "0", > "libelle": "Carte BEST CADEAUX 30 Euros", > "montantRemise": "", > "prixTotal": "00,00€" > }, > { > "id": "8a8b8d632481567f012481570364000d", > "prixAffiche": "15,00", > "quantite": "0", > "libelle": "Carte BEST CADEAUX 15 Euros", > "montantRemise": "", > "prixTotal": "00,00€" > } > ]} > > That's ... JSON, perfectlly formated. > Here's for the headers now: > HTTP/1.1 200 OK > Server Apache-Coyote/1.1 > X-Powered-By Servlet 2.4; JBoss-4.0.3SP1 (build: > CVSTag=JBoss_4_0_3_SP1 date=200510231054)/Tomcat-5.5 > Content-Type application/json;charset=UTF-8 > Content-Length 1221 > Date Tue, 08 Dec 2009 18:41:05 GMT > > Woot! What the hell am I missing ? Thanks for the great help you could > (and I hope, will) provide !!!
[jQuery] Re: $.ajax and $.get
On Nov 27, 12:44 pm, Wayne Tong wrote: > It is one of our internal server here, and don't think you will have access > to it, see the message it returns when I use $.ajax What Michael is trying to point out is that it's pretty difficult to debug something when we can't see either the page that's failing or the data that you are requesting. If you have the ability to at some public location post the output of the ajax request and a simple demo page that uses your code, you'd be more likely to get some useful help. Certainly repeating the error messages again doesn't add much. My first guess, though, is that the returned JSON is in some way formatted poorly. IE decides it knows what to do with it. FF throws its hands up in despair. -- Scott
[jQuery] Re: AJAX w/dataType='json', doesn't correctly handle boolean response?
I'm not explicitly setting a content-type, but Firebug tells me it's text/html . I'll try changing it to application/json. Erm... I must be doing something else wrong in my script. Just now I just set up a very simple test using both regular $.ajax() and using jquery.form.js's $.ajaxForm() and both work correctly. If anyone's interested, here are both test scripts: bool_json_test.html: http://www.w3.org/1999/xhtml";> AJAX JSON Test Return type: String Integer Float Boolean Null Data type returned: Value returned: $(function() { $("#click_me").click(function() { $.ajax({ url : 'bool_json_test.ajax.php', dataType : 'json', type : 'GET', data : { type: $("[name=datatype]:checked").val() }, success : function(json) { var text = (json===null) ? "null" : json.toString(); $("#data_type").text(typeof json); $("#value").text(""); $("#value").text(text); } }); }); }); Return type: String Integer Float Boolean Null Data type returned: Value returned: $(function() { $("#ajax_form").ajaxForm({ dataType : 'json', success : function(json) { var text = (json===null) ? "null" : json.toString(); $("#data_type2").text(typeof json); $("#value2").text(""); $("#value2").text(text); } }); }); bool_json_test.ajax.php: "Hello World", 'integer' => 5, 'float' => 10.3, 'boolean' => true, 'null' => NULL ); print json_encode($rets[$type]); ?> Thanks, Jamie On Nov 19, 10:19 pm, Michael Geary wrote: > You would normally expect that to work. > > What content-type is your server putting in the header for the JSON data? > That could be throwing it off. > > Also note that a bare primitive value (true, false, null, or a string or > number) is not valid JSON. The only valid JSON is either an object enclosed > in {} or an array enclosed in []. However, this is not what's causing your > problem. jQuery doesn't use a strict JSON parser - it simply evals the JSON > text - so a bare primitive value should work fine if everything else is OK. > > -Mike > > On Thu, Nov 19, 2009 at 11:08 AM, livefree75 wrote: > > Hi, > > > I'm using the following code on the client side: > > $.ajax({ > > dataType : 'json', > > // other options > > success : function(json_response) { > > console.log(typeof response, response); // Using Firefox's > > firebug > > } > > }); > > > And this PHP code on the server side: > > > > // php processing code > > $response = some_boolean_value(); > > print json_encode($response); > > ?> > > > Now, using Firebug, I can verify that the actual JSON response coming > > back is indeed either true or false (without the quotes), > > which should evaluate to Javascript boolean true or false. However, > > when I obtain it in the success() method of my $.ajax() call, it comes > > in as a string. (e.g. "true" or "false"). i.e., the console.log() > > call renders: string true > > > Shouldn't it render: boolean true ? > > > Is this a bug? > > Jamie
[jQuery] Re: Ajax download file.
Hi, i don't know how can you attach any other file but xml to HTTPresponse. I rather do sth like that: - load php file which return link to pdf - open new window with pdf file code: $.ajax({ type: "POST", url: "phpfile.php", data: param, success: function(html){ window.open(html); } }); On 16 Lis, 18:06, "m.ugues" wrote: > Hallo all. > I have a problem downloading a file via ajax. > > I contact via ajax a server-side component (i.e. Servlet) that creates > a pdf and attach it to the response. > When I receive the response I cannot pass the control to the browser. > > Any idea hot to make it? > > Kind regards > > Massimo
[jQuery] Re: Ajax download file.
Hi, i don't know how can you attach any other file but xml to HTTPresponse. I rather do sth like that: - load php file which return link to pdf - open new window with pdf file code: $.ajax({ type: "POST", url: "/Portfolio09/scripts/setLang.php", data: param, success: function(html){ window.open(html); } }); On 16 Lis, 18:06, "m.ugues" wrote: > Hallo all. > I have a problem downloading a file via ajax. > > I contact via ajax a server-side component (i.e. Servlet) that creates > a pdf and attach it to the response. > When I receive the response I cannot pass the control to the browser. > > Any idea hot to make it? > > Kind regards > > Massimo
[jQuery] Re: AJAX is not invoked for dynamically added input fields
Thanks man! So I changed this line to this to get it to work: //old $(".A, .B").keyup(function(event){ /new $(".A, .B").live ("keyup", function(event){... Thanks again for your quick answer! -Palgo On 11 Nov, 14:27, Giovanni Battista Lenoci wrote: > palgo ha scritto:> My problem is that while the calculation works on the > first to default > > rows, calculation doesn't seem to work on rows that I added by > > clicking on add row-button. > > > Anyone know why is happening? > > Do you use the live functionality also for the keyup event that will > fire the ajax call? > > Bye > > -- > gianiaz.net - web solutions > via piedo, 58 - 23020 tresivio (so) - italy > +39 347 7196482
[jQuery] Re: Ajax Load, CSS Insert on Loading Gif and Fade Out
Thankyou Nathan, I am sure this plugin and the filement group loading plugin are great, but I wanted a really lightweight solution that uses the css. If anyone knows how to set it up properly the chaining the etc (if possible using .empty()). Please post. I am sure there are others who would like a lightweight ahah solution. I am not interested in calling html through jquery with link to gif. Would like a flicker free loading gif that is already loaded through css Thanks from Josh On Nov 11, 2:30 am, Nathan Bubna wrote: > Why not just use something like this: > > http://plugins.jquery.com/project/loading >
[jQuery] Re: AJAX requests in progress
I found the answer in the source. $.active tells you how many requests are pending (just like Ajax.activeRequestCount in prototype). Thanks all, Alun Harford
Re: [jQuery] Re: $.ajax and responsed value...
thank´s -- From: "Josip Lazic" Sent: Saturday, November 07, 2009 4:02 PM To: "jQuery (English)" Subject: [jQuery] Re: $.ajax and responsed value... You could try return json encoded data from PHP, here's tutorial http://www.prodevtips.com/2008/08/15/jquery-json-with-php-json_encode-and-json_decode/
[jQuery] Re: $.ajax and responsed value...
You could try return json encoded data from PHP, here's tutorial http://www.prodevtips.com/2008/08/15/jquery-json-with-php-json_encode-and-json_decode/
[jQuery] Re: AJAX POST causing 500 unimplemented method
> Any idea what that "OPTIONS" and "500 unimplemented method" mean It sounds like somehow type got set to "OPTIONS" and when sent to the server it justifiably returned a "500 unimplemented" HTTP error code because it didn't know what to do with that method type. Take a look at the "more code here" stuff and see if somehow it was changed.
[jQuery] Re: AJAX POST causing 500 unimplemented method
What is the URL of the serviceUrl? Make sure that whatever resource it's going to it supports the POST verb. For example, if you POST to a .html resource, some servers will not accept it by default. You'd have to configure your server to allow it. On Nov 3, 1:53 pm, some_random_kid wrote: > I am using an AJAX POST, i.e.: > > $.ajax({ > url: serviceUrl, > async: false, > data: params, > type: "POST", > dataType: "xml", > > //more code here... > > }); > > But in the browser, I see that instead of a "POST" I see an "OPTIONS" > as well as a "500 unimplemented method." > > Any idea what that "OPTIONS" and "500 unimplemented method" mean?
[jQuery] Re: ajax not sending back details
There's something wrong in your server code: Parse error: syntax error, unexpected '[' in /home/lastings/ public_html/play/app/controllers/usersessions_controller.php on line 15 As for trapping the error in jQuery... this always works for me as an error catch: error: function(x, y, z) { // x.responseText is what the server is saying } On Nov 2, 11:55 am, numerical25 wrote: > I am trying to send data to a remove server via ajax. I am recieving the > xmlHttpRequest Object, but all of its properties are undefined or empty > > $('#testReq').click(function(){ > > alert('Button Works!'); > $.ajax({ > type: "POST", > url: "http://play.anthonylgordon.com/usersessions/store";, > data: 'data=Test', > error: function(e) { alert("Failure: " + > e.readystatechange ); }, > //Comes back undefined > success: function(msg){ > alert( "Data Saved: " + msg ); > > } > > }); > > }) > > I also tried > e.responseText > > and > > e.statusText > > and all of the other properties. what am i doing wrong > -- > View this message in > context:http://old.nabble.com/ajax-not-sending-back-details-tp26157740s27240p... > Sent from the jQuery General Discussion mailing list archive at Nabble.com.
[jQuery] Re: Ajax enabled Links/Forms and AutoRefresh
http://lmgtfy.com/?q=jquery+ajax Michel Belleville
[jQuery] Re: AJAX and JSON
yeah, if you are not using cross domain calls, dump the callback parameter there, it's totally no needed... and if you are not using cross domain, then you aren't/don't-need-to use or think about "jsonp" at all as for mime type of normal json: application/json or text/plain also works for fine (in my experiences anyways) On Oct 27, 6:49 am, Mark Volkmann wrote: > On Mon, Oct 26, 2009 at 9:58 PM, MorningZ wrote: > > > if this is your *exact* code > > > $.getJSON(url + "?callback?", function (json) { > > > then you're missing an equal sign > > > $.getJSON(url + "?callback=?", function (json) { > > Good catch! Fortunately I had the = in my real code. I just forgot to > type it in the email. > > > As for the rest of your issue of "what to do", this post should help: > > >http://groups.google.com/group/jquery-en/browse_thread/thread/fd821bf... > > Okay, I think I understand about using jsonp now. I don't think I need > it in my case though because my call isn't cross-site. So I still have > these questions: > > 1) What should the response type be when using jsonp? > 2) What should the response type be when not using jsonp? Is that just > called plain json? > 3) When not using jsonp, what should the server code return? Still > JavaScript code that calls the callback function with the json content > or just the json content? > > > > > On Oct 26, 8:14 pm, Mark Volkmann wrote: > >> I have some code working that invokes an HTTP service that returns JSON. > >> From my JavaScript I call the service with: > > >> $.getJSON(url + "?callback?", function (json) { > >> // do something with json here > > >> }); > > >> My service is implemented as a Java servlet with a doGet method. > >> In that method I: > >> 1) set the content type of the response to "application/x-javascript". > >> 2) get the value of the callback parameter > >> 3) create a Java Map > >> 4) use the org.json library to convert the map to JSON text > >> 5) build a string of JavaScript code that calls the callback function, > >> passing it the JSON > >> 6) write the string of JavaScript to the response > > >> Is this the recommended approach? I was expected that > >> I wouldn't need to pass the callback function name to the servlet and > >> could just return the JSON from the servlet instead of a string of > >> JavaScript code. > > -- > R. Mark Volkmann > Object Computing, Inc.
[jQuery] Re: AJAX and JSON
On Mon, Oct 26, 2009 at 9:58 PM, MorningZ wrote: > > if this is your *exact* code > > $.getJSON(url + "?callback?", function (json) { > > then you're missing an equal sign > > $.getJSON(url + "?callback=?", function (json) { Good catch! Fortunately I had the = in my real code. I just forgot to type it in the email. > As for the rest of your issue of "what to do", this post should help: > > http://groups.google.com/group/jquery-en/browse_thread/thread/fd821bf488c9a9d3?hl=en# Okay, I think I understand about using jsonp now. I don't think I need it in my case though because my call isn't cross-site. So I still have these questions: 1) What should the response type be when using jsonp? 2) What should the response type be when not using jsonp? Is that just called plain json? 3) When not using jsonp, what should the server code return? Still JavaScript code that calls the callback function with the json content or just the json content? > On Oct 26, 8:14 pm, Mark Volkmann wrote: >> I have some code working that invokes an HTTP service that returns JSON. >> From my JavaScript I call the service with: >> >> $.getJSON(url + "?callback?", function (json) { >> // do something with json here >> >> }); >> >> My service is implemented as a Java servlet with a doGet method. >> In that method I: >> 1) set the content type of the response to "application/x-javascript". >> 2) get the value of the callback parameter >> 3) create a Java Map >> 4) use the org.json library to convert the map to JSON text >> 5) build a string of JavaScript code that calls the callback function, >> passing it the JSON >> 6) write the string of JavaScript to the response >> >> Is this the recommended approach? I was expected that >> I wouldn't need to pass the callback function name to the servlet and >> could just return the JSON from the servlet instead of a string of >> JavaScript code. -- R. Mark Volkmann Object Computing, Inc.
[jQuery] Re: AJAX and JSON
if this is your *exact* code $.getJSON(url + "?callback?", function (json) { then you're missing an equal sign $.getJSON(url + "?callback=?", function (json) { As for the rest of your issue of "what to do", this post should help: http://groups.google.com/group/jquery-en/browse_thread/thread/fd821bf488c9a9d3?hl=en# On Oct 26, 8:14 pm, Mark Volkmann wrote: > I have some code working that invokes an HTTP service that returns JSON. > From my JavaScript I call the service with: > > $.getJSON(url + "?callback?", function (json) { > // do something with json here > > }); > > My service is implemented as a Java servlet with a doGet method. > In that method I: > 1) set the content type of the response to "application/x-javascript". > 2) get the value of the callback parameter > 3) create a Java Map > 4) use the org.json library to convert the map to JSON text > 5) build a string of JavaScript code that calls the callback function, > passing it the JSON > 6) write the string of JavaScript to the response > > Is this the recommended approach? I was expected that > I wouldn't need to pass the callback function name to the servlet and > could just return the JSON from the servlet instead of a string of > JavaScript code. > > -- > R. Mark Volkmann > Object Computing, Inc.
[jQuery] Re: AJAX API without XML?
Sure, jquery supports several popular response data types, not only xml, also HTML, text, jason even script. For more information, I suggest you check jquery official docs. Becoder. On Sun, Oct 18, 2009 at 1:21 AM, kidburla wrote: > > Hi, > > I understand that normally when you want to load a page into an area > of the page, you would use the ajax.load function within jQuery's AJAX > API. However what happens if you have an old-fashioned server which > does not support XML over HTTP? In other words it expects to receive > name=value parameters from the client and then returns an HTTPResponse > with just standard HTML in the body and some other headers? Can we > still use the AJAX API? If not, is there some plugin which allows me > to modify the standard AJAX functions to use standard HTTP Request/ > Response format (or "AJAH")? >
[jQuery] Re: AJAX & callbacks: load(); $.get() and $.post() do not
Hi, I have a related problem: http://groups.google.com/group/jquery-en/browse_thread/thread/faf44301f4a22535/537df7c5a5b124bf?lnk=gst&q=garcia.narbona#537df7c5a5b124bf I have just also found this: http://groups.google.com/group/jquery-en/browse_thread/thread/4c8e4ac00ee529d2# http://groups.google.com/group/jquery-en/browse_thread/thread/7f9ef1da3c7b6691# I don't know if theu are all related. I hope this helps in order to solve the problem. I will try to make the posts suggestions and I'll comment. Thanks. On 14 oct, 02:43, Ninad Desai wrote: > I use $.post and $.ajax and it always works for me. > Could you mention how you are passing parameters? > That might be holding the key. > > Ninad > > On Oct 13, 2:33 pm, James wrote: > > > Could you define "does not work"? Does the request get sent at all? > > > Without much information it's hard to help. What's in the variable > > 'parameters' and 'register_submitCallback'? > > > On Oct 13, 3:22 am, alexryan wrote: > > > > $.get() and $.post() functions work for me *except* when I supply a > > > callback function as the third parameter. > > > I can pass in exactly the same set of arguments that work for a load() > > > function to $.get() and $.post() and they do not work. > > > Has anyone else experienced this? > > > If so, does anyone have a work-around? > > > I'm using jQuery 1.3.2. > > > > For example ... > > > > This works ... > > > $('div.status').load('/quotations/RegisterServlet', parameters, > > > register_submitCallback); > > > > This does not work ... > > > $.post('/quotations/RegisterServlet', parameters, > > > register_submitCallback);
[jQuery] Re: AJAX & callbacks: load(); $.get() and $.post() do not
I use $.post and $.ajax and it always works for me. Could you mention how you are passing parameters? That might be holding the key. Ninad On Oct 13, 2:33 pm, James wrote: > Could you define "does not work"? Does the request get sent at all? > > Without much information it's hard to help. What's in the variable > 'parameters' and 'register_submitCallback'? > > On Oct 13, 3:22 am, alexryan wrote: > > > $.get() and $.post() functions work for me *except* when I supply a > > callback function as the third parameter. > > I can pass in exactly the same set of arguments that work for a load() > > function to $.get() and $.post() and they do not work. > > Has anyone else experienced this? > > If so, does anyone have a work-around? > > I'm using jQuery 1.3.2. > > > For example ... > > > This works ... > > $('div.status').load('/quotations/RegisterServlet', parameters, > > register_submitCallback); > > > This does not work ... > > $.post('/quotations/RegisterServlet', parameters, > > register_submitCallback);
[jQuery] Re: ajax request hangs IE6
I fixed this using the setting in the ajax request cache: false On Oct 13, 3:09 pm, rasensio wrote: > XP IE6 virtual PC for test, latest version of jquery > > the browser hangs after an ajax request. > > $.get("/myurl", {random: $.random()}, mycallback); > > I read that IE6 hangs for some cache searching stuff, that is why I > added a randomstring with my $.random() but keeps hanging the > browser. > > anyone with this issue ? > > thanks guys
[jQuery] Re: AJAX & callbacks: load(); $.get() and $.post() do not
Could you define "does not work"? Does the request get sent at all? Without much information it's hard to help. What's in the variable 'parameters' and 'register_submitCallback'? On Oct 13, 3:22 am, alexryan wrote: > $.get() and $.post() functions work for me *except* when I supply a > callback function as the third parameter. > I can pass in exactly the same set of arguments that work for a load() > function to $.get() and $.post() and they do not work. > Has anyone else experienced this? > If so, does anyone have a work-around? > I'm using jQuery 1.3.2. > > For example ... > > This works ... > $('div.status').load('/quotations/RegisterServlet', parameters, > register_submitCallback); > > This does not work ... > $.post('/quotations/RegisterServlet', parameters, > register_submitCallback);
[jQuery] Re: AJAX & callbacks: load(); $.get() and $.post() do not
Hi, it could be that your not supplying the type of return in the .post and .get calls. According to the API .post and .get have a fourth param of 'type' such as 'xml' or 'json'. This might not be the issue but it could be because your server won't know what mime type to return. DED On Tue, Oct 13, 2009 at 8:22 AM, alexryan wrote: > > $.get() and $.post() functions work for me *except* when I supply a > callback function as the third parameter. > I can pass in exactly the same set of arguments that work for a load() > function to $.get() and $.post() and they do not work. > Has anyone else experienced this? > If so, does anyone have a work-around? > I'm using jQuery 1.3.2. > > For example ... > > This works ... > $('div.status').load('/quotations/RegisterServlet', parameters, > register_submitCallback); > > This does not work ... > $.post('/quotations/RegisterServlet', parameters, > register_submitCallback);
[jQuery] Re: Ajax populating select box based on radio selected
that is a different issue than the ajax thing. but, it's also a common thing.. :) $("input[name='myradio']:checked").val() That should do it. Get the value of the checked radio option... I changed it to not use an ID, cuz chances are you are you are using a name and not an ID... Failing that, you could extend things a little and loop over each of the radios: $("input[name='myradio']").each( function () { if ($(this).attr("checked") == true) { radioValue = $(this).val(); //do something with the value // ... //no need to loop to the next item, //so return false to end the .each() return false; } }); The first approach is preferable, I'd think - less looping involved. But this second approach shows an expanded way to do the same thing, which is sometimes needed when doing something a little more non-simple. HTH Shawn lionel28 wrote: hummm, not that simple. It's multiple radios with multiple values so how to get id and value of selected one? lionel28 wrote: Thanks for replying. I am going to try your code. Shawn Grover wrote: in short, no. Not that I know of. I mean no plugin per se. The code/script is simple enough though... $("#myradio").click( function () { $.ajax({ url: "somepage.php", data: "id=somevalue", dataType: "json", success: function (results) { var opts = ""; for (x=0; x < results.length; x++) { opts += "" + results[x] + ""; } $("#mySelect").empty().append(opts); } }); }); that's kinda rough, but should get the point across. The results you get back from the ajax call can be whatever you want - a new HTML definition of the select element, a json array of objects, a simple array of text values (as hinted at in the sample code), or even xml. Whatever you pick for the results format dictates what you have to do with the results to get it into your select list. The flexibility and diversity of the approaches here are probably why there is no (known) plugin. Yet the code is simple enough to slap together in less than 5 minutes. HTH. Shawn lionel28 wrote: Hello, Is there a script that allows to get values to populate a select box via ajax when a radio button is clicked? Thank you.
[jQuery] Re: Ajax populating select box based on radio selected
hummm, not that simple. It's multiple radios with multiple values so how to get id and value of selected one? lionel28 wrote: > > Thanks for replying. > I am going to try your code. > > > Shawn Grover wrote: >> >> >> in short, no. Not that I know of. I mean no plugin per se. The >> code/script is simple enough though... >> >> $("#myradio").click( function () { >>$.ajax({ >> url: "somepage.php", >> data: "id=somevalue", >> dataType: "json", >> success: function (results) { >>var opts = ""; >>for (x=0; x < results.length; x++) { >> opts += "" + results[x] + ""; >>} >>$("#mySelect").empty().append(opts); >> } >>}); >> }); >> >> that's kinda rough, but should get the point across. The results you >> get back from the ajax call can be whatever you want - a new HTML >> definition of the select element, a json array of objects, a simple >> array of text values (as hinted at in the sample code), or even xml. >> Whatever you pick for the results format dictates what you have to do >> with the results to get it into your select list. >> >> The flexibility and diversity of the approaches here are probably why >> there is no (known) plugin. Yet the code is simple enough to slap >> together in less than 5 minutes. >> >> HTH. >> >> Shawn >> >> lionel28 wrote: >>> >>> Hello, >>> >>> Is there a script that allows to get values to populate a select box via >>> ajax when a radio button is clicked? >>> >>> Thank you. >> >> > > -- View this message in context: http://www.nabble.com/Ajax-populating-select-box-based-on-radio-selected-tp25869309s27240p25870135.html Sent from the jQuery General Discussion mailing list archive at Nabble.com.
[jQuery] Re: Ajax populating select box based on radio selected
Thanks for replying. I am going to try your code. Shawn Grover wrote: > > > in short, no. Not that I know of. I mean no plugin per se. The > code/script is simple enough though... > > $("#myradio").click( function () { >$.ajax({ > url: "somepage.php", > data: "id=somevalue", > dataType: "json", > success: function (results) { >var opts = ""; >for (x=0; x < results.length; x++) { > opts += "" + results[x] + ""; >} >$("#mySelect").empty().append(opts); > } >}); > }); > > that's kinda rough, but should get the point across. The results you > get back from the ajax call can be whatever you want - a new HTML > definition of the select element, a json array of objects, a simple > array of text values (as hinted at in the sample code), or even xml. > Whatever you pick for the results format dictates what you have to do > with the results to get it into your select list. > > The flexibility and diversity of the approaches here are probably why > there is no (known) plugin. Yet the code is simple enough to slap > together in less than 5 minutes. > > HTH. > > Shawn > > lionel28 wrote: >> >> Hello, >> >> Is there a script that allows to get values to populate a select box via >> ajax when a radio button is clicked? >> >> Thank you. > > -- View this message in context: http://www.nabble.com/Ajax-populating-select-box-based-on-radio-selected-tp25869309s27240p25870057.html Sent from the jQuery General Discussion mailing list archive at Nabble.com.
[jQuery] Re: Ajax populating select box based on radio selected
in short, no. Not that I know of. I mean no plugin per se. The code/script is simple enough though... $("#myradio").click( function () { $.ajax({ url: "somepage.php", data: "id=somevalue", dataType: "json", success: function (results) { var opts = ""; for (x=0; x < results.length; x++) { opts += "" + results[x] + ""; } $("#mySelect").empty().append(opts); } }); }); that's kinda rough, but should get the point across. The results you get back from the ajax call can be whatever you want - a new HTML definition of the select element, a json array of objects, a simple array of text values (as hinted at in the sample code), or even xml. Whatever you pick for the results format dictates what you have to do with the results to get it into your select list. The flexibility and diversity of the approaches here are probably why there is no (known) plugin. Yet the code is simple enough to slap together in less than 5 minutes. HTH. Shawn lionel28 wrote: Hello, Is there a script that allows to get values to populate a select box via ajax when a radio button is clicked? Thank you.
[jQuery] Re: Ajax - Disable script eval
Update: I ended up adding this line of code to my script: jQuery.globalEval = function(){}; I am still interested in advice if there's a better way. On Oct 11, 10:12 am, Christophe wrote: > I am using the jQuery load function to grab HTML from other pages. I > am only interested in the HTML and the scripts in the page are > irrelevant. How can I skip the scripts eval? > > I tried to add a filter but the following doesn't seem to work: > load("page.html *:not(script)") > > I was also considering overwriting the GlobalEval function (I don't > want to alter the jQuery library itself), but I don't know how to do > that... > > Thanks for your help!
[jQuery] Re: Ajax Request Order
I think that you could probably do something like this: //first get $.ajax({ type: "GET", url: "some.php", data: "name=John&location=Boston", success: function(){ //another get on success $.ajax({ type: "GET", url: "somepage2.php", data:"what=whatever", success: function(){ //do whatever here } }); } }); Basically what I did there was put the second get inside of the first get. It will only run after the first get was successful. Please let me know if you need any more help. On Oct 10, 5:07 pm, James W wrote: > Hello, > > I have a page that makes two ajax calls when the function is called. I > have noticed while testing the page that sometimes the second request > does not run, the first request works but then sometimes the second > ones gets skipped. > > Is there a way to make sure the second request fires only after the > first one? > > Here is my code below: > > > > function InsertOrder(id,tbl) { > $.ajaxSetup({dataType: "html"}) > > $.get('demo_orders.asp?PID=' + id + '&TBL=' + tbl,function(datanew) {$ > ('#pos-diner-left-mid').empty();$('#pos-diner-left-mid').append > (datanew);}) > > $.get('order_total.asp?TBL=' + tbl, function(datanew){$('#pos-header- > total').empty();$('#pos-header-total').append(datanew);}) > > } > > > > Thanks > > James
[jQuery] Re: Ajax related issue
I found the answer to my own question. To overcome this problem, I have to use the .live method to bind current and future elements on the page. I made the following change to my function to use the .live method.: jQuery.fn.checkmarkClickWithAjax = function(){ this.live("click",function(){ $(this).html(""); $.ajax({ url: this.href, dataType: "script" }); return false; }); return this; }; For more information see http://docs.jquery.com/Events/live
[jQuery] Re: Ajax Not Working A Second Time
Thanks for the info, I will look into that. Cheers - george On Oct 5, 12:21 pm, amuhlou wrote: > the .A1 within the #info divs does not exist when the document ready > event fires, so the click event is not applied. try using the live > method() > > http://docs.jquery.com/Events/live > > On Oct 5, 2:54 pm, GLSmyth wrote: > > > I have some simple code: > > > $(document).ready( > > function() { > > $('.A1').click( > > function() { > > $('#Info').load('Test_A1.htm'); > > } > > ); > > $('.A2').click( > > function() { > > $('#Info').load('Test_A2.htm'); > > } > > ); > > } > > ); > > > followed in the body with: > > > > > A1 > > A2 > > > > > > > Test_A1.htm is simply the following: > > > This is A1 > > Click this text to display Test_A2.htm > > > Test_A2.htm is the same as Test_A1.htm, only with the "1" and "2" > > values switched. > > > When I click on A1 or A2, the text from the associated files is loaded > > into #Info, so that works fine. However, when I click on the A1 or A2 > > class within #Info, nothing happens. > > > I guess I am missing something fundamental here, so it would be very > > helpful if someone could explain how I can get the text that is > > displayed within #Info "clickable" so that it can load the other file. > > > Thanks for your help. > > > george
[jQuery] Re: Ajax Not Working A Second Time
the .A1 within the #info divs does not exist when the document ready event fires, so the click event is not applied. try using the live method() http://docs.jquery.com/Events/live On Oct 5, 2:54 pm, GLSmyth wrote: > I have some simple code: > > $(document).ready( > function() { > $('.A1').click( > function() { > $('#Info').load('Test_A1.htm'); > } > ); > $('.A2').click( > function() { > $('#Info').load('Test_A2.htm'); > } > ); > } > ); > > followed in the body with: > > > A1 > A2 > > > > Test_A1.htm is simply the following: > > This is A1 > Click this text to display Test_A2.htm > > Test_A2.htm is the same as Test_A1.htm, only with the "1" and "2" > values switched. > > When I click on A1 or A2, the text from the associated files is loaded > into #Info, so that works fine. However, when I click on the A1 or A2 > class within #Info, nothing happens. > > I guess I am missing something fundamental here, so it would be very > helpful if someone could explain how I can get the text that is > displayed within #Info "clickable" so that it can load the other file. > > Thanks for your help. > > george
[jQuery] Re: AJAX load: scrolling
No, you can't postpone a DOM refresh as you describe. Your best bet is probably to wrap the table in a div that has a constant height, so the surrounding content remains in place as your table grows/shrinks. On Sun, Oct 4, 2009 at 4:21 PM, Dennis Madsen wrote: > > I've created some jQuery which remove many tr rows from my table and > inserts new via AJAX. This indicate that the page is scrolling because > first the table increase after elements is removed and afterwards it > grows when the new content is inserted. Is there a way to let jQuery > update this table without doing so? Eg. by first refreshing the DOM > after I finish my manipulation. > > Here is a bit of my code: > > $j(".bookingViewRow").each(function() { > $j(this).remove(); > }); > > $j.get('cajax.php', {}, function(html) { > $j("#bookingView").append(html); > }); > > Please tell me if you don't understand my problem!
[jQuery] Re: AJAX load: scrolling
Someone? On 5 Okt., 01:21, Dennis Madsen wrote: > I've created some jQuery which remove many tr rows from my table and > inserts new via AJAX. This indicate that the page is scrolling because > first the table increase after elements is removed and afterwards it > grows when the new content is inserted. Is there a way to let jQuery > update this table without doing so? Eg. by first refreshing the DOM > after I finish my manipulation. > > Here is a bit of my code: > > $j(".bookingViewRow").each(function() { > $j(this).remove(); > }); > > $j.get('cajax.php', {}, function(html) { > $j("#bookingView").append(html); > }); > > Please tell me if you don't understand my problem!
[jQuery] Re: ajax submit upload file firebug... no answer
> Effectively after uploading file we can't see any response in firebug. > (You can see an example in the official website of jquery form > pluginhttp://malsup.com/jquery/form/#code-samples) You won't see the response from a file upload displayed on the Firebug console tab because that request does not use ajax. You will see the request/response on Firebug's "Net" tab however. > And in the response i call a script with > > My page get this file well but i have a javascript error on the "$" of > $(document).ready(function() {... This is due to the nature of how the file upload is performed. As I said, it does not use ajax, however it simulates ajax by performing a native form submit and pointing the response to a dynamic iframe. So the response is actually received in a different document, and then the form plugin extracts it and passes the response data to your success handler. That dynamic iframe document does not have direct access to the jQuery $ fn. One way around this, as is noted in the documentation, is to return this response data inside a element (which the plugin knows how to handle). Another way to handle this is to embed you logic in the main document.
[jQuery] Re: .ajax() with dataType: 'jsonp' will not use error callback if request fails
> I think this is a known limitation of jsonp as a technique, not a bug > with jquery itself. Jsonp works by appending a script tag to the DOM, > whose "src" attribute points to the URL you specify. The URL is > expected to wrap a json object in a function call to the function you > specify, and the returned text is evaluated using eval().. Just like > script tags that are returned in the sorce HTML, if the server doesn't > respond (or throws a 404), I don't think there is a way to determine > that through JavaScript. > > $.ajax() can determine other error scenarios by inspecting the XHR > object, but jsonp doesn't use XHR. Hope that helps. Here's a jsonp function that handles errors and timeouts: http://gist.github.com/82181
[jQuery] Re: .ajax() with dataType: 'jsonp' will not use error callback if request fails
I think this is a known limitation of jsonp as a technique, not a bug with jquery itself. Jsonp works by appending a script tag to the DOM, whose "src" attribute points to the URL you specify. The URL is expected to wrap a json object in a function call to the function you specify, and the returned text is evaluated using eval().. Just like script tags that are returned in the sorce HTML, if the server doesn't respond (or throws a 404), I don't think there is a way to determine that through JavaScript. $.ajax() can determine other error scenarios by inspecting the XHR object, but jsonp doesn't use XHR. Hope that helps. On Oct 1, 12:18 pm, mrandall wrote: > I'm using an .ajax() call to do a jsonp request to another domain. > When the user is not logged in, however, the server will return a 401 > error. Unfortunately, this causes my .ajax() call to fail _without_ > calling the error callback. Is this a known bug? Here is my code: > > $.ajax({ > url: appData.API.workout.get, > data: {date: App.formatDate(date)}, > dataType: 'jsonp', > success: function(json) { > Data = json; > model.buildOrderedWorkout(); > myCP.Workout.View.initialize(); > }, > error: function(xOptions, error) { > > Controller.requestError(xOptions, error); > } > }); > > Is there a way to get this request to not fail? I also looked at the > jquery-jsonp plugin, but that didn't really work and did not return > the http status codes. > > Thanks for your help, > Mike
[jQuery] Re: Ajax results?
Thanks guys Michael, that link is very helpful. I got the numbers a bit mixed up, it should be around 25 result items each made up of 12 elements with around 12 pieces of information from db/json. - so yes, 300 elements total. If you don't mind me asking, I'd like you guys to give me your opinion on what I'm doing at the moment. I'm making a search page that has filters and the way I have it set up, I use jQuery to retrieve filter values and pass them along via AJAX to the server. The server takes these values, stores them in a session then outputs the results, which then is html()'ed to my results DIV. (I'll be switching to JSON) What do you guys think? Currently the whole search page is a bit javascript dependent (both the actual input/manipulation of filters and the instant update of the results). Should I be really worried about people who have javascript disabled? Thanks! On Sep 30, 4:34 pm, Michael Geary wrote: > 25 x 12 sounds closer to 300 elements? Either way, it's easy to generate > that much stuff in JavaScript and get good performance, if you're careful > about how you write the code. Here's a post with some tips and optimized > code for a similar task: > > http://groups.google.com/group/jquery-en/msg/121203c4216c34ee > > If you follow the basic pattern in that code it should be plenty fast. > > You could post the specific HTML you want to generate along with the JSON > format you plan to use if you have any questions about how to make it go > fast. > > -Mike > > On Wed, Sep 30, 2009 at 9:01 AM, Toaster wrote: > > > Thank you for your reply James > > > In regards to the JSON vs HTML, would the browser have any problems > > creating 25 results items each with 12 pieces of information from > > JSON? (it'd be more of less 120 elements being appended)
[jQuery] Re: ajax submit upload file firebug... no answer
Could you post some relevant code on how you're doing all of this? It's hard to help from only reading what you've described. On Oct 2, 5:48 am, Harold Martin wrote: > Hi, > > I've a technical problem, i use jQuery Form Plugin and it's working > well except for upload file. > Effectively after uploading file we can't see any response in firebug. > (You can see an example in the official website of jquery form > pluginhttp://malsup.com/jquery/form/#code-samples) > > And in the response i call a script with > > My page get this file well but i have a javascript error on the "$" of > $(document).ready(function() {... > I think it's because why don't have the first answer... > Do you have a idea? > > Thanx > > Harold
[jQuery] Re: Ajax / Form Validation
Try putting: var validation_options = {...}; outside of $(document).ready(); On Oct 1, 5:13 pm, "Dave Maharaj :: WidePixels.com" wrote: > This is my script now. > > > $(document).ready(function() { > > $('#testForm').bind('submit', function() { > $(this).validate(validation_options); > > var valid = $(this).valid(); > > if (valid) { > > var queryString = $('#testForm').formSerialize(); > //alert(queryString); > $(this).ajaxSubmit({ > type: 'post', > url: > '/manage/experiences/edit/123', > data: queryString, > target: '#testUpdate', > success: afterEffects > }); > > return false; > } > > }); > > function afterEffects () > { > $.fn.colorbox.close(); > } > var validation_options = { > // set your options here > rules: { > field: "required" > } > > }; > }); > > > > When I hit submit it tries to access the url by the browser. > > Check the net activity and see > > _method PUT > data[Experience][city] LosAngeles > data[Experience][country_id] 38 > data[Experience][finished] 2007 > data[Experience][position] Customer Service Rep > data[Experience][respons] sweet sf > data[Experience][start] 1975 > data[Experience][state_id] 15 > field > > Nothing is working. > > Ideas? > > Dave > > -Original Message- > From: James [mailto:james.gp@gmail.com] > Sent: October-02-09 12:19 AM > To: jQuery (English) > Subject: [jQuery] Re: Ajax / Form Validation > > Here's a simplified version of what you want to do: > > $('#testForm').bind('submit', function() { > $(this).validate(validation_options); > var valid = $(this).valid(); > if (valid) { > // do your ajax > } > }); > > var validation_options = { > // set your options here > }; > > On Oct 1, 10:52 am, "Dave Maharaj :: WidePixels.com" > wrote: > > I have a form that gets submitted via AJAX, now i want to add the > > validation but cant make sense of it. > > Using malsup form script to submit, > > > Now I would like to incorporate the jQuery Validation Plug-in found > > onhttp://jquery.bassistance.de/validate/demo/index.html > > > I currently have this so submit: > > > > > $(document).ready(function() { > > $('#testForm').live("click", function(){ > > $('#testForm').bind('submit', function() { > > var queryString = $('#testForm').formSerialize(); > > var id = '<?php echo $id; ?>'; > > > $(this).ajaxSubmit({ > > type: 'post', > > url: '/manage/experiences/edit/123', > > data: queryString, > > target: '#updateMe', > > success: afterEffects > > }); > > > return false; > > }); > > }); > > > function afterEffects () > > { > > $.fn.colorbox.close(); > > } > > > }) > > > > > > But how do I add in the validation script into this? Any help would be > > greatly appreciated. > > > Thanks > > > Dave > >
[jQuery] Re: Ajax / Form Validation
This is my script now. $(document).ready(function() { $('#testForm').bind('submit', function() { $(this).validate(validation_options); var valid = $(this).valid(); if (valid) { var queryString = $('#testForm').formSerialize(); //alert(queryString); $(this).ajaxSubmit({ type: 'post', url: '/manage/experiences/edit/123', data: queryString, target: '#testUpdate', success:afterEffects }); return false; } }); function afterEffects () { $.fn.colorbox.close(); } var validation_options = { // set your options here rules: { field: "required" } }; }); When I hit submit it tries to access the url by the browser. Check the net activity and see _method PUT data[Experience][city] LosAngeles data[Experience][country_id]38 data[Experience][finished] 2007 data[Experience][position] Customer Service Rep data[Experience][respons] sweet sf data[Experience][start] 1975 data[Experience][state_id] 15 field Nothing is working. Ideas? Dave -Original Message- From: James [mailto:james.gp@gmail.com] Sent: October-02-09 12:19 AM To: jQuery (English) Subject: [jQuery] Re: Ajax / Form Validation Here's a simplified version of what you want to do: $('#testForm').bind('submit', function() { $(this).validate(validation_options); var valid = $(this).valid(); if (valid) { // do your ajax } }); var validation_options = { // set your options here }; On Oct 1, 10:52 am, "Dave Maharaj :: WidePixels.com" wrote: > I have a form that gets submitted via AJAX, now i want to add the > validation but cant make sense of it. > Using malsup form script to submit, > > Now I would like to incorporate the jQuery Validation Plug-in found > onhttp://jquery.bassistance.de/validate/demo/index.html > > I currently have this so submit: > > > $(document).ready(function() { > $('#testForm').live("click", function(){ > $('#testForm').bind('submit', function() { > var queryString = $('#testForm').formSerialize(); > var id = '<?php echo $id; ?>'; > > $(this).ajaxSubmit({ > type: 'post', > url: '/manage/experiences/edit/123', > data: queryString, > target: '#updateMe', > success: afterEffects > }); > > return false; > }); > }); > > function afterEffects () > { > $.fn.colorbox.close(); > } > > }) > > > > But how do I add in the validation script into this? Any help would be > greatly appreciated. > > Thanks > > Dave
[jQuery] Re: Ajax / Form Validation
Here's a simplified version of what you want to do: $('#testForm').bind('submit', function() { $(this).validate(validation_options); var valid = $(this).valid(); if (valid) { // do your ajax } }); var validation_options = { // set your options here }; On Oct 1, 10:52 am, "Dave Maharaj :: WidePixels.com" wrote: > I have a form that gets submitted via AJAX, now i want to add the validation > but cant make sense of it. > Using malsup form script to submit, > > Now I would like to incorporate the jQuery Validation Plug-in found > onhttp://jquery.bassistance.de/validate/demo/index.html > > I currently have this so submit: > > > $(document).ready(function() { > $('#testForm').live("click", function(){ > $('#testForm').bind('submit', function() { > var queryString = $('#testForm').formSerialize(); > var id = ''; > > $(this).ajaxSubmit({ > type: 'post', > url: '/manage/experiences/edit/123', > data: queryString, > target: '#updateMe', > success: afterEffects > }); > > return false; > }); > }); > > function afterEffects () > { > $.fn.colorbox.close(); > } > > }) > > > > But how do I add in the validation script into this? Any help would be > greatly appreciated. > > Thanks > > Dave
[jQuery] Re: ajax complete function not being called
What happens if you put the whole $.ajax statement in a try/catch statement? Does it catch? On Oct 1, 7:24 am, mike wrote: > Right! I'm having the same problem--neither the error nor the > complete are being called. The request just fails, probably because > the responseText is not JSON. > > I've had no luck searching around for answers to this either. Guess > we'll have to wait until the jQuery JSONP plugin is more mature. > ( ._.) > > Mike > > On Sep 28, 9:13 pm, Alex wrote: > > > I'm making a call to a Twitter JSON feed, and when I pass an incorrect > > username, jQuery's ajax complete method never gets called. > > > An example of a JSON response that causes complete not to be called > > (nor error, nor success) > > is:http://twitter.com/users/show.json?screen_name=bhdjbhubeuhfbfbjfbjf > > > Here's my code: > > > $.ajax({ > > type: "GET", > > url: "http://twitter.com/users/show.json";, > > cache: false, > > data: "screen_name=" + $('#account-id').val().replace(/^\s*|\s*$/ > > g,''), > > dataType: "jsonp", > > async: true, > > success: function(j){ > > alert('success'); > > }, > > error: function(xhr, ajaxOptions, thrownError) { > > alert(xhr + ' ' + ajaxOptions + ' ' + thrownError); > > }, > > complete: function() { > > alert('finished'); > > } > > > }); > > > Any ideas on why the complete method isn't getting called? > > > Shouldn't this always get called? > > > Thanks! > >
[jQuery] Re: ajax complete function not being called
Right! I'm having the same problem--neither the error nor the complete are being called. The request just fails, probably because the responseText is not JSON. I've had no luck searching around for answers to this either. Guess we'll have to wait until the jQuery JSONP plugin is more mature. ( ._.) Mike On Sep 28, 9:13 pm, Alex wrote: > I'm making a call to a Twitter JSON feed, and when I pass an incorrect > username, jQuery's ajax complete method never gets called. > > An example of a JSON response that causes complete not to be called > (nor error, nor success) > is:http://twitter.com/users/show.json?screen_name=bhdjbhubeuhfbfbjfbjf > > Here's my code: > > $.ajax({ > type: "GET", > url: "http://twitter.com/users/show.json";, > cache: false, > data: "screen_name=" + $('#account-id').val().replace(/^\s*|\s*$/ > g,''), > dataType: "jsonp", > async: true, > success: function(j){ > alert('success'); > }, > error: function(xhr, ajaxOptions, thrownError) { > alert(xhr + ' ' + ajaxOptions + ' ' + thrownError); > }, > complete: function() { > alert('finished'); > } > > }); > > Any ideas on why the complete method isn't getting called? > > Shouldn't this always get called? > > Thanks!
[jQuery] Re: ajax complete function not being called
Right! I'm having the same problem--neither the error nor the complete are being called. The request just fails, probably because the responseText is not JSON. I've had no luck searching around for answers to this either. Guess we'll have to wait until the jQuery JSONP plugin is more mature. ( ._.) Mike On Sep 28, 9:13 pm, Alex wrote: > I'm making a call to a Twitter JSON feed, and when I pass an incorrect > username, jQuery's ajax complete method never gets called. > > An example of a JSON response that causes complete not to be called > (nor error, nor success) > is:http://twitter.com/users/show.json?screen_name=bhdjbhubeuhfbfbjfbjf > > Here's my code: > > $.ajax({ > type: "GET", > url: "http://twitter.com/users/show.json";, > cache: false, > data: "screen_name=" + $('#account-id').val().replace(/^\s*|\s*$/ > g,''), > dataType: "jsonp", > async: true, > success: function(j){ > alert('success'); > }, > error: function(xhr, ajaxOptions, thrownError) { > alert(xhr + ' ' + ajaxOptions + ' ' + thrownError); > }, > complete: function() { > alert('finished'); > } > > }); > > Any ideas on why the complete method isn't getting called? > > Shouldn't this always get called? > > Thanks!
[jQuery] Re: Ajax results?
25 x 12 sounds closer to 300 elements? Either way, it's easy to generate that much stuff in JavaScript and get good performance, if you're careful about how you write the code. Here's a post with some tips and optimized code for a similar task: http://groups.google.com/group/jquery-en/msg/121203c4216c34ee If you follow the basic pattern in that code it should be plenty fast. You could post the specific HTML you want to generate along with the JSON format you plan to use if you have any questions about how to make it go fast. -Mike On Wed, Sep 30, 2009 at 9:01 AM, Toaster wrote: > > Thank you for your reply James > > In regards to the JSON vs HTML, would the browser have any problems > creating 25 results items each with 12 pieces of information from > JSON? (it'd be more of less 120 elements being appended) >
[jQuery] Re: Ajax results?
I can't really say. It varies depending on what you're trying to put in and how you're doing it. For example, inserting 120 large tables versus 120 lines of text will probably have a noticeable difference. And how you're doing it. For example, inserting everything at once, or set a timeout to insert one-by-one (x-by-x). Inserting everything at once might freeze the user's browser for a while (again, this depends on the content being put it) and then everything appears at once, as oppose to the content taking longer to display but it's displaying progressively to the user (probably a better experience). And all this also depends on the user's browser and computer specs. It's best just try it out for yourself and see. You could post some code and we can help optimize it. On Sep 30, 6:01 am, Toaster wrote: > Thank you for your reply James > > In regards to the JSON vs HTML, would the browser have any problems > creating 25 results items each with 12 pieces of information from > JSON? (it'd be more of less 120 elements being appended)
[jQuery] Re: Ajax results?
Thank you for your reply James In regards to the JSON vs HTML, would the browser have any problems creating 25 results items each with 12 pieces of information from JSON? (it'd be more of less 120 elements being appended)
[jQuery] Re: Ajax results?
You should use JSON if you have a set of data that you want to easily parse (e.g. loop through) and put into a format of your own (via Javascript). You should use HTML if you have a block of HTML to just insert into the page, or if you just return very short and simple data, like "true" or "false" or "1", etc. If you return HTML with an element, it will not download the image automatically with your AJAX response. When you insert the HTML onto the page (the DOM), the browser will render the HTML and download the image at that point in time. On Sep 29, 4:42 pm, Toaster wrote: > Hello > > I got a couple questions concerning the use of AJAX for setting > filters and generating results. > > -- When retrieving results, should I go json or html? each result item > consists of more of less 7 elements, should I be generating this > server-side (html) or clien-side (js)? > > -- Lets say I go html and there are images in the results. When it > comes to the success part of the ajax call, does it mean it downloaded > the images as well or just the html code? > > Thanks in advance.
[jQuery] Re: Ajax post on save dialog box
hi, Firebug was telling me that editcomment was not defined and the dialog was freezing. So I put editcomment, cid and pagetext in bracket and the dialog box updated the div, closed but database was not updated Thanks lionel28 wrote: > > Hi, > > I am loading tiny Mce editor in a dialog box which updates the div on > save > I am trying to save in database > > 'Save Comment': function() { > var content = tinyMCE.get('editor').getContent(); > > $.ajax({ > type: "POST", > url: "comments.php", > data: "do=editcomment&c=+ cid +&pagetext=+ content +" > }); > > Alert placed before the ajax call shows that I get the cid and the > pagetext > Alert placed after the ajax call are also successful. So my problem is > the ajax call which is not sending any data. > > Please someone, what is the best way to post? > > Thank you. > -- View this message in context: http://www.nabble.com/Ajax-post-on-save-dialog-box-tp25656699s27240p25658296.html Sent from the jQuery General Discussion mailing list archive at Nabble.com.
[jQuery] Re: Ajax post on save dialog box
Hi Please try this var content = jQuery.trim(tinyMCE.get('editor').getContent()); $.post("comments.php", { do : editcomment , c : cid , pagetext : content }, function(data){ }); Best Regards Ranga On Tue, Sep 29, 2009 at 9:48 AM, lionel28 wrote: > > > Hi, > > I am loading tiny Mce editor in a dialog box which updates the div on save > I am trying to save in database > > 'Save Comment': function() { > var content = tinyMCE.get('editor').getContent(); > > $.ajax({ > type: "POST", > url: "comments.php", > data: "do=editcomment&c=+ cid +&pagetext=+ content +" > }); > > Alert placed before the ajax call shows that I get the cid and the pagetext > Alert placed after the ajax call are also successful. So my problem is the > ajax call which is not sending any data. > > Please someone, what is the best way to post? > > Thank you. > -- > View this message in context: > http://www.nabble.com/Ajax-post-on-save-dialog-box-tp25656699s27240p25656699.html > Sent from the jQuery General Discussion mailing list archive at Nabble.com. > >
[jQuery] Re: Ajax check username - ASP and Access DB
OK, now got the backend working with the following code: <%...@language="VBSCRIPT"%> <% Dim rsUser__MMColParam rsUser__MMColParam = "1" If (Request.Form("username") <> "") Then rsUser__MMColParam = Request.Form("username") End If %> <% Dim rsUser Dim rsUser_numRows Set rsUser = Server.CreateObject("ADODB.Recordset") rsUser.ActiveConnection = MM_car_STRING rsUser.Source = "SELECT UserName FROM Users WHERE UserName = '" + Replace(rsUser__MMColParam, "'", "''") + "'" rsUser.CursorType = 0 rsUser.CursorLocation = 2 rsUser.LockType = 1 rsUser.Open() rsUser_numRows = 0 %> <% If Not rsUser.EOF Or Not rsUser.BOF Then %> 1 <% End If ' end Not rsUser.EOF Or NOT rsUser.BOF %> <% rsUser.Close() Set rsUser = Nothing %> On Sep 28, 10:40 pm, factoringcompare wrote: > Thank you James that worked. I can now move on and try and code the DB > connection. > > On Sep 28, 10:22 pm, James wrote: > > > > > When you return "response" in your AJAX, it's not "1". It's > > "...". jQuery doesn't automatically go through your > > HTML and look in the body to find the "1". > > In your server-side code, you don't return the whole HTML page. You > > just return the String "1" (without the quotes). Such that if you load > > up check10.asp, and view its source, all you see is a "1". That's it. > > > In your AJAX response conditional check, you want to do > > if (response == "1") > > (with the double-quotes) > > Otherwise, you're checking for an integer. What's returned is a String > > type. > > > On Sep 28, 10:31 am, factoringcompare > > wrote: > > > > OK, thank you for taking the time out to look at this issue for me. Ok > > > this is the code client side page: > > > > > > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";> > > > http://www.w3.org/1999/xhtml";> > > > > > > > > > Ajax Username Checker - Using JQuery > > > > > > #username{ > > > padding:3px; > > > font-size:18px; > > > border:3px #CCC solid; > > > > } > > > > #tick{display:none} > > > #cross{display:none} > > > > > > > > > > > > > $(document).ready(function(){ > > > $('#username').keyup(username_check); > > > > }); > > > > function username_check(){ > > > > var username = $('#username').val(); > > > > if(username == "" || username.length < 4){ > > > $('#username').css('border', '3px #CCC solid'); > > > $('#tick').hide(); > > > > }else{ > > > > jQuery.ajax({ > > > type: "POST", > > > url: "check10.asp", > > > data: 'username='+ username, > > > cache: false, > > > success: function(response){ > > > if(response == 1){ > > > $('#username').css('border', '3px #C33 solid'); > > > $('#tick').hide(); > > > $('#cross').fadeIn(); > > > }else{ > > > $('#username').css('border', '3px #090 solid'); > > > $('#cross').hide(); > > > $('#tick').fadeIn(); > > > } > > > > } > > > }); > > > } > > > } > > > > > > > > > > > > > > > > > > Username: > > > > > width="16" height="16"/> > > > > > width="16" height="16"/> > > > > > > > > > > > The file is posted here:http://www.factoringcompare.com/test1.asp > > > > The server side code:http://www.factoringcompare.com/check10.asp > > > > > > > > > Untitled Document > > > > > > > > > > > > > 1 > > > > > > > > > > If I am following the code correctly by putting a "1" on check10.asp > > > the script should return that the username is taken. Which it is not > > > > On Sep 28, 9:05 pm, MorningZ wrote: > > > > > Why do you have a page with a php extension? > > > > > As for helping further, it would be a huge help if you post some non- > > > > working code... you could have a bad selector, bad syntax, who > > > > knows... > > > > > On Sep 28, 3:15 pm, factoringcompare > > > > wrote: > > > > > > I can’t get it to work. Something strange is happening. > > > > > > To manually check if the client side code is working I put “1” in the > > > > > server side page with a .php extension and sure enough I can get the > > > > > code to work. If I do the same with a .asppage it has no effect. Any > > > > > thoughts what’s going on? > > > > > > On Sep 28, 7:36 pm, MorningZ wrote: > > > > > > > "This is the php code I can't mimic: " > > > > > > > Really? the code is super simple: > > > > > > > - Open connection to the database > > > > > > - Take the posted value of "username", trim it, and make lower case > > > > > > - Clean up the string to help prevent SQL injection attack > > > > > > - Take that username and check against the database > > > > > > - echo (Response.Write) the number of rows found > > > > > > - Close the database connection > > > > > > > On Sep 28, 1:26 pm, factoringcompare > > > > > > wrote: > > > > > > > > OK, I am trying to get this example to work > > > > > > > :http://papermashup.com/jquery-php-mysql-username-availability-checker/ > > > > > > > > This is the php code I can't mimic: > > > > > > > > > > > > > > include("dbConnector.php"); > > > > > > > $connector = new DbConnector(); > > > >
[jQuery] Re: Ajax check username - ASP and Access DB
Thank you James that worked. I can now move on and try and code the DB connection. On Sep 28, 10:22 pm, James wrote: > When you return "response" in your AJAX, it's not "1". It's > "...". jQuery doesn't automatically go through your > HTML and look in the body to find the "1". > In your server-side code, you don't return the whole HTML page. You > just return the String "1" (without the quotes). Such that if you load > up check10.asp, and view its source, all you see is a "1". That's it. > > In your AJAX response conditional check, you want to do > if (response == "1") > (with the double-quotes) > Otherwise, you're checking for an integer. What's returned is a String > type. > > On Sep 28, 10:31 am, factoringcompare > wrote: > > > > > OK, thank you for taking the time out to look at this issue for me. Ok > > this is the code client side page: > > > > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";> > > http://www.w3.org/1999/xhtml";> > > > > > > Ajax Username Checker - Using JQuery > > > > #username{ > > padding:3px; > > font-size:18px; > > border:3px #CCC solid; > > > } > > > #tick{display:none} > > #cross{display:none} > > > > > > > > > $(document).ready(function(){ > > $('#username').keyup(username_check); > > > }); > > > function username_check(){ > > > var username = $('#username').val(); > > > if(username == "" || username.length < 4){ > > $('#username').css('border', '3px #CCC solid'); > > $('#tick').hide(); > > > }else{ > > > jQuery.ajax({ > > type: "POST", > > url: "check10.asp", > > data: 'username='+ username, > > cache: false, > > success: function(response){ > > if(response == 1){ > > $('#username').css('border', '3px #C33 solid'); > > $('#tick').hide(); > > $('#cross').fadeIn(); > > }else{ > > $('#username').css('border', '3px #090 solid'); > > $('#cross').hide(); > > $('#tick').fadeIn(); > > } > > > } > > }); > > } > > } > > > > > > > > > > > > > Username: > > > width="16" height="16"/> > > > width="16" height="16"/> > > > > > > > > The file is posted here:http://www.factoringcompare.com/test1.asp > > > The server side code:http://www.factoringcompare.com/check10.asp > > > > > > Untitled Document > > > > > > > > > 1 > > > > > > > If I am following the code correctly by putting a "1" on check10.asp > > the script should return that the username is taken. Which it is not > > > On Sep 28, 9:05 pm, MorningZ wrote: > > > > Why do you have a page with a php extension? > > > > As for helping further, it would be a huge help if you post some non- > > > working code... you could have a bad selector, bad syntax, who > > > knows... > > > > On Sep 28, 3:15 pm, factoringcompare > > > wrote: > > > > > I can’t get it to work. Something strange is happening. > > > > > To manually check if the client side code is working I put “1” in the > > > > server side page with a .php extension and sure enough I can get the > > > > code to work. If I do the same with a .asppage it has no effect. Any > > > > thoughts what’s going on? > > > > > On Sep 28, 7:36 pm, MorningZ wrote: > > > > > > "This is the php code I can't mimic: " > > > > > > Really? the code is super simple: > > > > > > - Open connection to the database > > > > > - Take the posted value of "username", trim it, and make lower case > > > > > - Clean up the string to help prevent SQL injection attack > > > > > - Take that username and check against the database > > > > > - echo (Response.Write) the number of rows found > > > > > - Close the database connection > > > > > > On Sep 28, 1:26 pm, factoringcompare > > > > > wrote: > > > > > > > OK, I am trying to get this example to work > > > > > > :http://papermashup.com/jquery-php-mysql-username-availability-checker/ > > > > > > > This is the php code I can't mimic: > > > > > > > > > > > > include("dbConnector.php"); > > > > > > $connector = new DbConnector(); > > > > > > > $username = trim(strtolower($_POST['username'])); > > > > > > $username = mysql_escape_string($username); > > > > > > > $query = "SELECT username FROM usernameCheck WHERE username = > > > > > > '$username' LIMIT 1"; > > > > > > $result = $connector->query($query); > > > > > > $num = mysql_num_rows($result); > > > > > > > echo $num; > > > > > > mysql_close(); > > > > > > > On Sep 28, 2:16 pm, MorningZ wrote: > > > > > > > > Take an example page in php that you want to mimic, and simply > > > > > > > have > > > > > > >aspsend back to the browser the same information > > > > > > > > On Sep 28, 3:58 am, factoringcompare > > > > > > > > > > > > > > wrote: > > > > > > > > > Hi, > > > > > > > > > Reasonably new to web building. I am now just updating my site > > > > > > > > with > > > > > > > > jQuery (first time user). > > > > > > > > > I would like to implement an Ajax username checker on a new > > > > > > > > client > > > > > > > > registration form. All the tutorials and examples I ca
[jQuery] Re: Ajax check username - ASP and Access DB
When you return "response" in your AJAX, it's not "1". It's "...". jQuery doesn't automatically go through your HTML and look in the body to find the "1". In your server-side code, you don't return the whole HTML page. You just return the String "1" (without the quotes). Such that if you load up check10.asp, and view its source, all you see is a "1". That's it. In your AJAX response conditional check, you want to do if (response == "1") (with the double-quotes) Otherwise, you're checking for an integer. What's returned is a String type. On Sep 28, 10:31 am, factoringcompare wrote: > OK, thank you for taking the time out to look at this issue for me. Ok > this is the code client side page: > > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";> > http://www.w3.org/1999/xhtml";> > > > Ajax Username Checker - Using JQuery > > #username{ > padding:3px; > font-size:18px; > border:3px #CCC solid; > > } > > #tick{display:none} > #cross{display:none} > > > > > $(document).ready(function(){ > $('#username').keyup(username_check); > > }); > > function username_check(){ > > var username = $('#username').val(); > > if(username == "" || username.length < 4){ > $('#username').css('border', '3px #CCC solid'); > $('#tick').hide(); > > }else{ > > jQuery.ajax({ > type: "POST", > url: "check10.asp", > data: 'username='+ username, > cache: false, > success: function(response){ > if(response == 1){ > $('#username').css('border', '3px #C33 solid'); > $('#tick').hide(); > $('#cross').fadeIn(); > }else{ > $('#username').css('border', '3px #090 solid'); > $('#cross').hide(); > $('#tick').fadeIn(); > } > > } > }); > } > } > > > > > > > > Username: > width="16" height="16"/> > width="16" height="16"/> > > > > > The file is posted here:http://www.factoringcompare.com/test1.asp > > The server side code:http://www.factoringcompare.com/check10.asp > > > Untitled Document > > > > > 1 > > > > If I am following the code correctly by putting a "1" on check10.asp > the script should return that the username is taken. Which it is not > > On Sep 28, 9:05 pm, MorningZ wrote: > > > Why do you have a page with a php extension? > > > As for helping further, it would be a huge help if you post some non- > > working code... you could have a bad selector, bad syntax, who > > knows... > > > On Sep 28, 3:15 pm, factoringcompare > > wrote: > > > > I can’t get it to work. Something strange is happening. > > > > To manually check if the client side code is working I put “1” in the > > > server side page with a .php extension and sure enough I can get the > > > code to work. If I do the same with a .asppage it has no effect. Any > > > thoughts what’s going on? > > > > On Sep 28, 7:36 pm, MorningZ wrote: > > > > > "This is the php code I can't mimic: " > > > > > Really? the code is super simple: > > > > > - Open connection to the database > > > > - Take the posted value of "username", trim it, and make lower case > > > > - Clean up the string to help prevent SQL injection attack > > > > - Take that username and check against the database > > > > - echo (Response.Write) the number of rows found > > > > - Close the database connection > > > > > On Sep 28, 1:26 pm, factoringcompare > > > > wrote: > > > > > > OK, I am trying to get this example to work > > > > > :http://papermashup.com/jquery-php-mysql-username-availability-checker/ > > > > > > This is the php code I can't mimic: > > > > > > > > > > include("dbConnector.php"); > > > > > $connector = new DbConnector(); > > > > > > $username = trim(strtolower($_POST['username'])); > > > > > $username = mysql_escape_string($username); > > > > > > $query = "SELECT username FROM usernameCheck WHERE username = > > > > > '$username' LIMIT 1"; > > > > > $result = $connector->query($query); > > > > > $num = mysql_num_rows($result); > > > > > > echo $num; > > > > > mysql_close(); > > > > > > On Sep 28, 2:16 pm, MorningZ wrote: > > > > > > > Take an example page in php that you want to mimic, and simply have > > > > > >aspsend back to the browser the same information > > > > > > > On Sep 28, 3:58 am, factoringcompare > > > > > > wrote: > > > > > > > > Hi, > > > > > > > > Reasonably new to web building. I am now just updating my site > > > > > > > with > > > > > > > jQuery (first time user). > > > > > > > > I would like to implement an Ajax username checker on a new client > > > > > > > registration form. All the tutorials and examples I can find use > > > > > > > jQuery and php. Unfortunately, I have taught myself Access > > > > > > > andASPand > > > > > > > have no knowledge of php. At this stage I want to stick withASPand > > > > > > > Access and look to upgrade the DB as another project. > > > > > > > > Can any body point me in the right direction to obtain some code. > > > > > > > > Kind regards.- Hide quoted text - > > > > > > > - Show quoted text -- Hide quoted
[jQuery] Re: Ajax check username - ASP and Access DB
OK, thank you for taking the time out to look at this issue for me. Ok this is the code client side page: http://www.w3.org/1999/xhtml";> Ajax Username Checker - Using JQuery #username{ padding:3px; font-size:18px; border:3px #CCC solid; } #tick{display:none} #cross{display:none} $(document).ready(function(){ $('#username').keyup(username_check); }); function username_check(){ var username = $('#username').val(); if(username == "" || username.length < 4){ $('#username').css('border', '3px #CCC solid'); $('#tick').hide(); }else{ jQuery.ajax({ type: "POST", url: "check10.asp", data: 'username='+ username, cache: false, success: function(response){ if(response == 1){ $('#username').css('border', '3px #C33 solid'); $('#tick').hide(); $('#cross').fadeIn(); }else{ $('#username').css('border', '3px #090 solid'); $('#cross').hide(); $('#tick').fadeIn(); } } }); } } Username: The file is posted here: http://www.factoringcompare.com/test1.asp The server side code: http://www.factoringcompare.com/check10.asp Untitled Document 1 If I am following the code correctly by putting a "1" on check10.asp the script should return that the username is taken. Which it is not On Sep 28, 9:05 pm, MorningZ wrote: > Why do you have a page with a php extension? > > As for helping further, it would be a huge help if you post some non- > working code... you could have a bad selector, bad syntax, who > knows... > > On Sep 28, 3:15 pm, factoringcompare > wrote: > > > > > I can’t get it to work. Something strange is happening. > > > To manually check if the client side code is working I put “1” in the > > server side page with a .php extension and sure enough I can get the > > code to work. If I do the same with a .asppage it has no effect. Any > > thoughts what’s going on? > > > On Sep 28, 7:36 pm, MorningZ wrote: > > > > "This is the php code I can't mimic: " > > > > Really? the code is super simple: > > > > - Open connection to the database > > > - Take the posted value of "username", trim it, and make lower case > > > - Clean up the string to help prevent SQL injection attack > > > - Take that username and check against the database > > > - echo (Response.Write) the number of rows found > > > - Close the database connection > > > > On Sep 28, 1:26 pm, factoringcompare > > > wrote: > > > > > OK, I am trying to get this example to work > > > > :http://papermashup.com/jquery-php-mysql-username-availability-checker/ > > > > > This is the php code I can't mimic: > > > > > > > > include("dbConnector.php"); > > > > $connector = new DbConnector(); > > > > > $username = trim(strtolower($_POST['username'])); > > > > $username = mysql_escape_string($username); > > > > > $query = "SELECT username FROM usernameCheck WHERE username = > > > > '$username' LIMIT 1"; > > > > $result = $connector->query($query); > > > > $num = mysql_num_rows($result); > > > > > echo $num; > > > > mysql_close(); > > > > > On Sep 28, 2:16 pm, MorningZ wrote: > > > > > > Take an example page in php that you want to mimic, and simply have > > > > >aspsend back to the browser the same information > > > > > > On Sep 28, 3:58 am, factoringcompare > > > > > wrote: > > > > > > > Hi, > > > > > > > Reasonably new to web building. I am now just updating my site with > > > > > > jQuery (first time user). > > > > > > > I would like to implement an Ajax username checker on a new client > > > > > > registration form. All the tutorials and examples I can find use > > > > > > jQuery and php. Unfortunately, I have taught myself Access andASPand > > > > > > have no knowledge of php. At this stage I want to stick withASPand > > > > > > Access and look to upgrade the DB as another project. > > > > > > > Can any body point me in the right direction to obtain some code. > > > > > > > Kind regards.- Hide quoted text - > > > > > > - Show quoted text -- Hide quoted text - > > > > - Show quoted text -- Hide quoted text - > > - Show quoted text -
[jQuery] Re: Ajax check username - ASP and Access DB
Why do you have a page with a php extension? As for helping further, it would be a huge help if you post some non- working code... you could have a bad selector, bad syntax, who knows... On Sep 28, 3:15 pm, factoringcompare wrote: > I can’t get it to work. Something strange is happening. > > To manually check if the client side code is working I put “1” in the > server side page with a .php extension and sure enough I can get the > code to work. If I do the same with a .asp page it has no effect. Any > thoughts what’s going on? > > On Sep 28, 7:36 pm, MorningZ wrote: > > > "This is the php code I can't mimic: " > > > Really? the code is super simple: > > > - Open connection to the database > > - Take the posted value of "username", trim it, and make lower case > > - Clean up the string to help prevent SQL injection attack > > - Take that username and check against the database > > - echo (Response.Write) the number of rows found > > - Close the database connection > > > On Sep 28, 1:26 pm, factoringcompare > > wrote: > > > > OK, I am trying to get this example to work > > > :http://papermashup.com/jquery-php-mysql-username-availability-checker/ > > > > This is the php code I can't mimic: > > > > > > include("dbConnector.php"); > > > $connector = new DbConnector(); > > > > $username = trim(strtolower($_POST['username'])); > > > $username = mysql_escape_string($username); > > > > $query = "SELECT username FROM usernameCheck WHERE username = > > > '$username' LIMIT 1"; > > > $result = $connector->query($query); > > > $num = mysql_num_rows($result); > > > > echo $num; > > > mysql_close(); > > > > On Sep 28, 2:16 pm, MorningZ wrote: > > > > > Take an example page in php that you want to mimic, and simply have > > > > asp send back to the browser the same information > > > > > On Sep 28, 3:58 am, factoringcompare > > > > wrote: > > > > > > Hi, > > > > > > Reasonably new to web building. I am now just updating my site with > > > > > jQuery (first time user). > > > > > > I would like to implement an Ajax username checker on a new client > > > > > registration form. All the tutorials and examples I can find use > > > > > jQuery and php. Unfortunately, I have taught myself Access and ASP and > > > > > have no knowledge of php. At this stage I want to stick with ASP and > > > > > Access and look to upgrade the DB as another project. > > > > > > Can any body point me in the right direction to obtain some code. > > > > > > Kind regards.- Hide quoted text - > > > > > - Show quoted text -- Hide quoted text - > > > - Show quoted text -
[jQuery] Re: Ajax check username - ASP and Access DB
I can’t get it to work. Something strange is happening. To manually check if the client side code is working I put “1” in the server side page with a .php extension and sure enough I can get the code to work. If I do the same with a .asp page it has no effect. Any thoughts what’s going on? On Sep 28, 7:36 pm, MorningZ wrote: > "This is the php code I can't mimic: " > > Really? the code is super simple: > > - Open connection to the database > - Take the posted value of "username", trim it, and make lower case > - Clean up the string to help prevent SQL injection attack > - Take that username and check against the database > - echo (Response.Write) the number of rows found > - Close the database connection > > On Sep 28, 1:26 pm, factoringcompare > wrote: > > > > > OK, I am trying to get this example to work > > :http://papermashup.com/jquery-php-mysql-username-availability-checker/ > > > This is the php code I can't mimic: > > > > include("dbConnector.php"); > > $connector = new DbConnector(); > > > $username = trim(strtolower($_POST['username'])); > > $username = mysql_escape_string($username); > > > $query = "SELECT username FROM usernameCheck WHERE username = > > '$username' LIMIT 1"; > > $result = $connector->query($query); > > $num = mysql_num_rows($result); > > > echo $num; > > mysql_close(); > > > On Sep 28, 2:16 pm, MorningZ wrote: > > > > Take an example page in php that you want to mimic, and simply have > > > asp send back to the browser the same information > > > > On Sep 28, 3:58 am, factoringcompare > > > wrote: > > > > > Hi, > > > > > Reasonably new to web building. I am now just updating my site with > > > > jQuery (first time user). > > > > > I would like to implement an Ajax username checker on a new client > > > > registration form. All the tutorials and examples I can find use > > > > jQuery and php. Unfortunately, I have taught myself Access and ASP and > > > > have no knowledge of php. At this stage I want to stick with ASP and > > > > Access and look to upgrade the DB as another project. > > > > > Can any body point me in the right direction to obtain some code. > > > > > Kind regards.- Hide quoted text - > > > > - Show quoted text -- Hide quoted text - > > - Show quoted text -
[jQuery] Re: Ajax check username - ASP and Access DB
"This is the php code I can't mimic: " Really? the code is super simple: - Open connection to the database - Take the posted value of "username", trim it, and make lower case - Clean up the string to help prevent SQL injection attack - Take that username and check against the database - echo (Response.Write) the number of rows found - Close the database connection On Sep 28, 1:26 pm, factoringcompare wrote: > OK, I am trying to get this example to work > :http://papermashup.com/jquery-php-mysql-username-availability-checker/ > > This is the php code I can't mimic: > > include("dbConnector.php"); > $connector = new DbConnector(); > > $username = trim(strtolower($_POST['username'])); > $username = mysql_escape_string($username); > > $query = "SELECT username FROM usernameCheck WHERE username = > '$username' LIMIT 1"; > $result = $connector->query($query); > $num = mysql_num_rows($result); > > echo $num; > mysql_close(); > > On Sep 28, 2:16 pm, MorningZ wrote: > > > Take an example page in php that you want to mimic, and simply have > > asp send back to the browser the same information > > > On Sep 28, 3:58 am, factoringcompare > > wrote: > > > > Hi, > > > > Reasonably new to web building. I am now just updating my site with > > > jQuery (first time user). > > > > I would like to implement an Ajax username checker on a new client > > > registration form. All the tutorials and examples I can find use > > > jQuery and php. Unfortunately, I have taught myself Access and ASP and > > > have no knowledge of php. At this stage I want to stick with ASP and > > > Access and look to upgrade the DB as another project. > > > > Can any body point me in the right direction to obtain some code. > > > > Kind regards.- Hide quoted text - > > > - Show quoted text -
[jQuery] Re: Ajax check username - ASP and Access DB
OK, I am trying to get this example to work : http://papermashup.com/jquery-php-mysql-username-availability-checker/ This is the php code I can't mimic: query($query); $num = mysql_num_rows($result); echo $num; mysql_close(); On Sep 28, 2:16 pm, MorningZ wrote: > Take an example page in php that you want to mimic, and simply have > asp send back to the browser the same information > > On Sep 28, 3:58 am, factoringcompare > wrote: > > > > > Hi, > > > Reasonably new to web building. I am now just updating my site with > > jQuery (first time user). > > > I would like to implement an Ajax username checker on a new client > > registration form. All the tutorials and examples I can find use > > jQuery and php. Unfortunately, I have taught myself Access and ASP and > > have no knowledge of php. At this stage I want to stick with ASP and > > Access and look to upgrade the DB as another project. > > > Can any body point me in the right direction to obtain some code. > > > Kind regards.- Hide quoted text - > > - Show quoted text -
[jQuery] Re: Ajax check username - ASP and Access DB
Take an example page in php that you want to mimic, and simply have asp send back to the browser the same information On Sep 28, 3:58 am, factoringcompare wrote: > Hi, > > Reasonably new to web building. I am now just updating my site with > jQuery (first time user). > > I would like to implement an Ajax username checker on a new client > registration form. All the tutorials and examples I can find use > jQuery and php. Unfortunately, I have taught myself Access and ASP and > have no knowledge of php. At this stage I want to stick with ASP and > Access and look to upgrade the DB as another project. > > Can any body point me in the right direction to obtain some code. > > Kind regards.
[jQuery] Re: Ajax problem on Safari/Chrome browsers
That would make sense, since `do` is a language keyword: do { code to be executed } while (var <= endvalue); I am sure there is a way to escape it, though in the same way I am fearful of using if/else/for/while/var and all the test as name/value pairs in JS or jQ, I would look to change it. I have for a long time used 'act' which to me works better than do, as do means positive action, so you get into cases where you will see do=noprocess, or do=donotprocess, the cases of double-negative can lead to confusion. act={add, update, delete, inset} that all is pretty clear. Sorry I was not more help, just my opinion. -- Scott * If you contact me off list replace talklists@ with scott@ * On Sep 27, 2009, at 5:37 AM, indre1 wrote: After 3 DAYS, I finally figured it out: $.get('profile.php', { do: 'addfriend', id: userId } The problem is, that the word "do" is reserved or something, thus you can't use it in get, ajax and probably elsewhere. test.php? do=something will never work from jQuery then, or how should I escape it? Is this a bug or just something everyone has to know? Strangely, on FF it all worked. $.get('profile.php', { action: 'addfriend', id: userId } works perfectly. On Sep 27, 1:27 pm, indre1 wrote: Well, the problem still seems to be in the get() function. For example, IE gives the following error: Object doesn't support this property or method With: (function($) { $.fn.followUser = function(userId) { this.fadeOut(250, function(){ $.get('profile.php', { do: "addfriend", id: userId }, function (data){ return this.html('Follower addedp>').fadeIn(250); }); }); } })(jQuery); If I remove the whole $.get() part, the error is gone. Chrome will start fading out too. The code will then look like: (function($) { $.fn.followUser = function(userId) { this.fadeOut(250, function(){ }); } })(jQuery); I even tried replace the get() with ajax(), but ran into the same problem. Btw, thanks for the attr('rel') suggestion. This is something I was also looking for, but couldn't figure it out :) The html is now: $(function(){ $('div#followButton a').click(function(){$('div#followButton a').followUser($ (this).attr('rel'));});}); ... test1 On Sep 26, 6:48 pm, Matt Quackenbush wrote: @ Mike - Thanks for making me take a closer look at the original code. I get it now. My bad. /me crawls back into his cave to hibernate some more