doutongfu9484 2012-03-18 20:07
浏览 44
已采纳

zend框架中异步和异步请求的URL

I have a problem when sending asynchronous request to server, the url of server append to the current url and so the url will be incorrect!

I have anchors that send synchronous get request to controller using this way

<a href="<?php echo $this->url(array('module'=>'visits','controller'=>'visit','action'=>'index', 'page'=>'add'),NULL,TRUE); ?>" class="addVisit">Add new visit</a>

when I click over it the url becomes

 http://inspectionsys/visits/visit/index/page/add

When I click on another button that send asynchronous request to server using ajax

jQuery.ajax({
    url: "visit/get-visits",
    type: "POST",
    dataType: 'json',
    data: requestDate,
    success: successCallback,
    error:failureCallback
});

the URL becomes like this

http://inspectionsys/visits/visit/index/page/visit/get-visits

The url must be like this

http://inspectionsys/visits/visit/get-visits

Any suggestions??

  • 写回答

1条回答 默认 最新

  • doufu4333 2012-03-18 20:51
    关注

    The URL is being appended because you are using a relative link instead of an absolute one. Change your ajax call to this:

    jQuery.ajax({
        url: "/visit/get-visits",
        type: "POST",
        dataType: 'json',
        data: requestDate,
        success: successCallback,
        error:failureCallback
    });
    

    (note the leading slash on the URL).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题