console.log("whatever") will print in the debugger "whatever" without the "ugly" alert. Chrome dev extension, Explorer developer tools, firefox log, firebug, etc all work fine with console.log().
At this point try to log (or to "alert") $(this).attr('action'), $(this).serialize() and see if there are any errors. I'm not a javascript guru to tell you right away why your $.post doesn't work, but debugging step-by-step it's always useful. PS: instead of returning false, use preventDefault() ....it's kinda the recommended way to prevent the form submission. Also, if $.post fails you won't see anything. use .always() just to see if for example the .post failed ....submit(function(event) { event.preventDefault(); console.log('the form was clicked') var thepost = $.post(url, data); thepost.always(function(data) { console.log('the .post was fired and succeeded') }); }) On Wednesday, February 20, 2013 12:35:57 PM UTC+1, AnnG wrote: > > Hi > No it would appear that the $.post is not fired. I replaced the code with > > $form.submit(function(){ > alert("Hello - the form.submit ran"); > $.post($(this).attr('action'), $(this).serialize(), > function(response){ > alert("Hello - the post ran"); > },'json'); > > return false; > }); > > and the 'Hello - the form.submit ran' alert appears, but the other alert > 'Hello - the post ran' does not. > > I thought the action had run, as I had achieved one of my goals which was > to stay on the same page after the submit. > ...but it must have just fired the action from the form declaration: > <form id="scaninstance_form" action="{{=URL('add_new_scan')}}" > method="post"> > > I'm not familiar with using console.log() > > Ann > > On Tue, Feb 19, 2013 at 5:10 PM, Niphlod <nip...@gmail.com > <javascript:>>wrote: > >> if the .load isn't fired, then it's possible that the first one >> >> $.post($(this).attr('action'), $(this).serialize() ...... >> >> , isn't fired either ? >> did you debug it adding a console.log() or an alert() ? >> Can you confirm that this $.post is fired and returns something ? >> >> >> On Tuesday, February 19, 2013 5:59:07 PM UTC+1, AnnG wrote: >> >>> Thanks. Sorry about the delay in response. >>> In answer to your question, the .load function does not get called, >>> that is, the body of the function(response) does not appear to get called. >>> I tried just the line: >>> $('#scan_info_previous').hide;** and the div element with that ID does >>> not become hidden. >>> The 'action' is called OK though, and the db update in that action >>> ('add_new_scan') does take place. >>> >>> In answer to your point about using the nice web2py facilities, I feel >>> that I had to avoid these in places, as I have a recursive function to >>> generate a dynamic form which has divs within divs (so that I can have >>> collapsing/expanding form elements depending on the value of their parent >>> input elements). >>> If you can show me a way to use the web2py facilities, I would prefer >>> this. >>> >>> Regards, Ann >>> >>> >>> >>> On Thu, Feb 14, 2013 at 3:22 PM, Niphlod <nip...@gmail.com> wrote: >>> >>>> easier to read, still impossible to reproduce. You're doing everything >>>> without using the nice facilities web2py provides, but since you're going >>>> that way, let's try to break up and analyze the issue. >>>> You're attaching a submit handler and discarding completely the >>>> response >>>> >>>> $.post($(this).attr('action'), $(this).serialize(), function(response){ >>>> ************ THIS PART NOT WORKING - START ************** >>>> $('#scan_info_previous').load(**"{{=URL('get_patient_scan_* >>>> *info')}}", document.getElementById("**hidden_patient_id").value); >>>> OR I've also tried... >>>> ajax('{{=URL('get_patient_**scan_info')}}',['hidden_**patient_id'], >>>> 'scan_info_previous'); >>>> ************ THIS PART NOT WORKING - END ************** >>>> },'json'); >>>> >>>> what you're sending to the action url is the inputs serialized as >>>> json..... and until here, there should be no issues. >>>> When the action url returns something, scan_info_previous should be >>>> filled with the contents coming from what url ? Here it seems that it's >>>> the >>>> get_patient_scan_info ..... but you seem to want to pass along the >>>> "hidden_patient_id" parameter with that, and $(element).load() is a jquery >>>> function that doesn't work the same as the ajax() one that is coded within >>>> web2py. We don't know how your "get_patient_scan_info" works to give you >>>> the details on how to pass something to that. Have you at least checked >>>> that the request to get_patient_scan_info is being fired (i.e. you have >>>> problems firing the actual request or managing it at web2py's level)? >>>> >>>> >>>> On Thursday, February 14, 2013 3:26:05 PM UTC+1, AnnG wrote: >>>>> >>>>> Sorry, I've now attached the code as a file. >>>>> I corrected that error, thanks. ....Still doesn't work. >>>>> >>>>> >>>>> On Thursday, February 14, 2013 1:01:46 PM UTC, Niphlod wrote: >>>>>> >>>>>> meh, next time include the code as an attachment or use the google >>>>>> group interface that can format code inline...far more readable! >>>>>> Anyway, I'm at work and can't test it (nor anyone, without models, >>>>>> controllers, and so on), but I spotted an error >>>>>> >>>>>> $('scan_info_previous').load(" >>>>>> {{=URL('get_patient_scan_info'****)}}", >>>>>> document.getElementById("**hidde**n_patient_id").value); >>>>>> >>>>>> if you refer to something like <div id="scan_info_previous"></div> >>>>>> the jquery selector is >>>>>> $('#scan_info_previous') not $('scan_info_previous') >>>>>> >>>>>> >>>>>> -- >>>> >>>> --- >>>> You received this message because you are subscribed to the Google >>>> Groups "web2py-users" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to web2py+un...@**googlegroups.com. >>>> >>>> For more options, visit >>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out> >>>> . >>>> >>>> >>>> >>> >>> -- >> >> --- >> You received this message because you are subscribed to the Google Groups >> "web2py-users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to web2py+un...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.