I believe the official response header content type is "application/json", which is what @jsonify uses (I recommend using that rather than setting the header and using the json module directly).
Having the content type set to "text/json" is one possible explanation for the inconsistencies you described, so let us know if that fixes it. Take care, Eric 2011/7/29 Krishnakant Mane <[email protected]> > Hi cornelius, > Yes tried with return false in the click event .still the browser keeps > giving same save as dialog box > happy hacking > krishnakant > > On 29/07/11 15:40, Cornelius Kölbel wrote: > >> Hi Krishnakant, >> >> I think this is not a plyons issue, but a javascript issue. >> >> The javscript function that performs the ajax call and processes the >> json response should end with a >> >> return false; >> >> >> $('#submit').click(function(){ >> $('#voucher').ajaxSubmit(**options);//on submit button click >> event >> return false; >> }); >> >> Then your browser does not try to display/save the json resonse. >> >> Moreover: If you are dealing with JSON, i recommend using firefox and >> the jsonview plugin! >> >> Kind regards >> Cornelius >> >> Am 29.07.2011 11:58, schrieb Krishnakant Mane: >> >>> Hello all. >>> I have recently observed that when an action returns json instead of a >>> mako template, the behaviour is highly inconsistent. >>> The problem is like this. >>> One of my mako template sends an ajax submit request (using jquery) to >>> an action controller. >>> >>> Users of jquery will know that we use some kind of an after submit >>> event to process the returned json object. >>> in my case it is called success function. >>> Now what is happening is the following. >>> I often get a save dialog when the success function fires after submit. >>> I know its a json object that my action controller returns. >>> >>> As a part of investigation, I did download that text file. >>> I found that the text file exactly contains the key: value pare that >>> should have been otherwise processed safely as json. >>> Meaning the problem seems to be between the communication from >>> action to the mako template. >>> Is there any known inconsistency with ajax submit? >>> or am I missing a trick? >>> I am paisting the code snippit of the controller action and that part >>> of the mako template which is concerned with processing of the >>> returned jason. >>> Note that in my action, I don't have an @jsonify at the top. >>> This is compensated by the dumps function used in the controller. >>> The decision to do so is because once I had removed @jsonify and it >>> started to work. >>> But again this problem and I don't know why. >>> Actually we are approaching a deadline and this error has again come >>> up unexpectedly. >>> So we as a team are really desperately looking for some pointer. >>> Any help will be appreciated more than gold and silver. >>> >>> following is the controller action. >>> This is an accounting software and the code I am paisting is the >>> action that calls a rpc method from another server. >>> This action saves a transaction between 2 accounts. >>> It does so by sending the data to the rpc server. >>> Here goes the code. >>> >>> >>> def setVoucher(self): >>> c.flag = "n" >>> # Add Contra Voucher. >>> if c.flag == "n": >>> >>> #self.vouchertype =request.params["voucherflag"] >>> # get current date >>> #print request.params >>> self.date=str(strftime("%Y-%m-**%d %H:%M:%S")) >>> self.datepicker = request.params["dated"] + "-" + >>> request.params["datem"] + "-" + request.params["datey"] >>> date_of_transaction = >>> datetime.datetime.strptime(**str(self.datepicker),"%d-%m-%** >>> Y").strftime("%Y-%m-%d >>> %H:%M:%S") >>> >>> self.queryParams_master=[str(**request.params["reference_no"]** >>> ),self.date,date_of_**transaction,request.params["**narration"]] >>> #print self.queryParams_master >>> >>> self.queryParams_details = [] >>> length = request.params["rowslength"] >>> >>> >>> for i in range(1,int(length)): >>> >>> if str(request.params["crdr"+str(**i)]) == 'Cr': >>> queryParams_details >>> =[request.params["crdr"+str(i)**],request.params["acc"+str(i)]** >>> ,request.params["cr"+str(i)]] >>> if str(request.params["crdr"+str(**i)]) == 'Dr': >>> queryParams_details >>> =[request.params["crdr"+str(i)**],request.params["acc"+str(i)]** >>> ,request.params["dr"+str(i)]] >>> self.queryParams_details.**append(queryParams_details) >>> >>> #print request.params["vouchertype_**flag"] >>> self.queryParams=[request.**params["vouchertype_flag"]] >>> >>> trial = >>> app_globals.server_proxy.**cashbook.setCashBook(self.** >>> queryParams_master,self.**queryParams_details,session["**gnukhata"]) >>> res = >>> app_globals.server_proxy.**voucher.setVoucher(self.** >>> queryParams,session["gnukhata"**]) >>> >>> if res == True: >>> for r in self.queryParams_details: >>> if r[0] == 'Cr': >>> >>> app_globals.server_proxy.**account.updateAccountBalance([** >>> r[1],r[2],'craccount'],**session["gnukhata"]) >>> else: >>> >>> app_globals.server_proxy.**account.updateAccountBalance([** >>> r[1],r[2],'draccount'],**session["gnukhata"]) >>> >>> #print self.queryParams >>> data = {"message":"Voucher has been >>> saved","vouchertype_flag":**self.queryParams} >>> response.headers["Content-**Type"] = "text/json" >>> return simplejson.dumps(data) >>> >>> Look at the way headers are set and the call to the dumps. >>> >>> Now the concerned mako code. >>> >>> >>> Look at the success function. >>> YOu can easily see whats going on there, and I guess it was pritty >>> streight forward. >>> Yet this problem. >>> >>> >>> var options = { >>> >>> beforeSubmit: validateForm, // pre-submit callback >>> success: function(data){ >>> //the below code just appends the value fromm the key message to the >>> span called voucher_warning. >>> $("#voucher_warning").append(**data["message"]); >>> //alert(data["vouchertype_**flag"]); >>> document.getElementById("**vouchertype_flag").value = >>> data["vouchertype_flag"]; >>> acc=[]; >>> total_credit = 0; >>> total_debit = 0; >>> var table = document.getElementById("**dataTable"); >>> var rowCount = parseInt(table.rows.length) - parseInt(2); >>> for(var i=1; i<rowCount; i++) >>> { >>> table.deleteRow(i); >>> rowCount--; >>> i--; >>> } >>> document.getElementById("**total_credit_row").innerHTML = >>> "0.00"; >>> document.getElementById("**total_debit_row").innerHTML = >>> "0.00"; >>> $("input#reference_no").focus(**); >>> }, >>> clearForm:true // clear all form fields after successful submit >>> >>> }; >>> >>> $('#submit').click(function(){ >>> $('#voucher').ajaxSubmit(**options);//on submit button click event >>> }); >>> >>> >>> >>> Happy hacking. >>> Krishnakant. >>> >>> >>> >>> >> > -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To post to this group, send email to > pylons-discuss@googlegroups.**com<[email protected]> > . > To unsubscribe from this group, send email to pylons-discuss+unsubscribe@* > *googlegroups.com <pylons-discuss%[email protected]>. > For more options, visit this group at http://groups.google.com/** > group/pylons-discuss?hl=en<http://groups.google.com/group/pylons-discuss?hl=en> > . > > -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
