Sunday 15 May 2011

php - Yii framework, pass jquery parameters into Yii::app()->createUrl('controller/action',array('param'=>'value') -


I'm new to yii and I have this script in my script:

  $ ( On '#div_exams' (' click ',' a [id = "download]], function (e) {e.preventDefault (); var filename = e.target.id; $ .ajax ({Type:" POST ", url:" & lt ;? Php echo Yii :: app () - & gt; createUrl ("Exam / Download Exem", Arrays ('fileName' = & gt; 'I need to pass FILENAME here' );; & Gt; ", success: function (Jason Response) {}, error: function () {}});});   

So my question is, how can I pass a var file name in javascript to create url in yii?

Thank you very much :)

  var baseUrl = & lt ;? Php echo json_encode (Yii: app () - createUrl ("test / download exem", array ('filename' = & gt; '__ placeholder__'))); ? & Gt ;; $ ('Click', 'a [id ^ = "download]]', function (e) {... var url = baseUrl.replace ('__ placeholder__', encoderic monument (filename) on $ ('# div_exams' ) Option 2, Probably Cleaner: Create each URL in Yii, attach it as a link, read it using JS:  
  // When creating each download link: Lt ;? php echo CHtml :: link ('download link,' some url '', array ('id' = & gt; 'download_1234', 'data-download' => Yii:: app () - & Gt; createUrl ("Exam / Download Exem", Sir Mr. ( 'filename' = & gt; 'file'))))); // script $ ('# div_exams') ',' A [id ^ = "download"] ', function (e) {... var url = $ (this) .data (' download '); ...}   

Note that neither the solution is in the id attributes like you are now doing.

No comments:

Post a Comment