Reputation: 163
I have a YII view with an AJAX script in the page
<script>
$(".tasks-add").click(function(){
$.ajax({
type: 'get',
url: '<?php echo $this->createUrl('field')?>',
data: {
index: 1
},
});
});
</script>
Now this JS is making a call in the normal URL style(http://myapp/task/field?index=1
) though I have made use of YII urlManager to optimize for the 'path' style of URLs using:
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
I am getting a 'Bad request error' because the URL requested by AJAX is the old ugly ?arg=value1 style. Is there a way possible to make the AJAX call URL not have the query string like ?index=1
but like http://myapp/task/field/index/1
Upvotes: 0
Views: 311
Reputation: 4114
The YII way
<script>
$(".tasks-add").click(function(){
$.ajax({
type: 'get',
url: '<?php echo $this->createUrl('field',array('index'=>1));?>'
});
</script>
OR
<script>
$(".tasks-add").click(function(){
<?php echo CHtml::ajax(array(
'url'=>array('field','index'=>1),
'type'=>'get',
));?>
});
</script>
Upvotes: 2
Reputation: 7898
Just concatenate the URL string. jQuery ajax by default will append query string parameters when using GET and including data.
Upvotes: 1
Reputation: 97717
Yes. do it manually.
<script>
$(".tasks-add").click(function(){
$.ajax({
type: 'get',
url: '<?php echo $this->createUrl('field')?>'+'/index/1'
});
</script>
Upvotes: 1