douye2036 2015-07-18 16:35
浏览 29
已采纳

如何在服务器文件(如php)不存在时创建ajax请求?

i was developing sharetronix script but there is something realy odd about this script i can see in console network request goes for example for this address

http://localhost/ajax/postform-submit/ajaxtp:xml/r:0

but i cant find any folder with postform-submit name.i know this is possible with redirection using htaccess but i cant find anything in htaccess file.

this is part of js code where this request send

function postform_submit_step4()
{
    var req = ajax_init(true);
    if( ! req ) { return; }
    var p   = "post_temp_id="+encodeURIComponent(pf_data.temp_id)+"&message="+encodeURIComponent(pf_data.message);
    if( pf_data.existing_post_id != "" ) {
        p   += "&editpost="+encodeURIComponent(pf_data.existing_post_id);
    }
    else if( pf_data.share_with_type == "user" ) {
        p   += "&username="+encodeURIComponent(pf_data.share_with_xtra);
    }
    else if( pf_data.share_with_type == "group" ) {
        p   += "&groupname="+encodeURIComponent(pf_data.share_with_xtra);
    }
    if( pf_data.at_link[0] ) {
        p   += "&at_link="+encodeURIComponent(pf_data.at_link[0]);
    }
    if( pf_data.at_image[0] ) {
        p   += "&at_image="+encodeURIComponent(pf_data.at_image[0]);
    }
    if( pf_data.at_file[0] ) {
        p   += "&at_file="+encodeURIComponent(pf_data.at_file[0]);
    }
    if( pf_data.at_videoembed[0] ) {
        p   += "&at_videoembed="+encodeURIComponent(pf_data.at_videoembed[0]);
    }
    req.onreadystatechange  = function() {
        if( req.readyState != 4  ) { return; }
        if( ! req.responseXML ) { return; }
        var data    = req.responseXML.getElementsByTagName("result");
        if( !data || !data[0] ) { return; }
        data    = data[0];
        var status  = data.getElementsByTagName("status");
        var message = data.getElementsByTagName("message");
        if( !status || !status[0] || !message || !message[0] ) {
            return;
        }
        status  = status[0].firstChild.nodeValue;
        message = message[0].firstChild.nodeValue;
        if( status != "OK" ) {
            d.getElementById("pf_postederror_msg").innerHTML    = message;
            postform_htmlobject_hide("pf_posting");
            postform_htmlobject_show("pf_postederror", 36);
            postform_htmlobject_show("pf_mainpart", 114, function() { pf_open_state=1; pf_post_state=3; d.post_form.message.disabled=false; d.post_form.message.focus(); });
            return;
        }
        d.getElementById("pf_postedok_msg").innerHTML   = message;
        postform_htmlobject_hide("pf_posting");
        postform_htmlobject_show("pf_postedok", 36, function() { pf_open_state=0; pf_post_state=1; postform_statusmsg_setTimeout(); });
        var btn = d.getElementById("postform_open_button");
        if(btn) {
            btn.style.display   = "";
        }
        if( posts_synchronize ) {
            posts_synchronize();
        }
        var pinf    = pf_data.existing_post_id;
        if( pinf != "" ) {
            pinf    = pinf.split("_");
            var tmp = w.location.href.toString();
            tmp = tmp.replace(/^http(s)?\:\/\//, "");
            tmp = tmp.substr(tmp.indexOf("/"));
            var mtch    = "/view/"+(pinf[0]=="public"?"post":"priv")+":"+pinf[1];
            if( tmp.substr(0,mtch.length)==mtch ) {
                if( viewpost_synchronize ) {
                    viewpost_synchronize();
                }
                else {
                    w.location.href = w.location.href.toString();
                }
            }
        }
    }
    req.open("POST", siteurl+"ajax/postform-submit/ajaxtp:xml/r:"+Math.round(Math.random()*1000), true);
    req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    req.send(p);
}

how is this possible when there is no redirection?

  • 写回答

1条回答 默认 最新

  • duanri1985 2015-07-18 16:46
    关注

    The script is not odd: the way an URL maps to a file not always is so straightforward.

    Most web frameworks, for example, use a router/dispatcher to decide what to do/which file to serve given a specific URL.

    For example, most MVC web frameworks by default would handle this URL:

    http://www.example.com/users/edit/5 
    

    by calling the action/method "edit" of the controller "users" passing an argument 5.

    Long story short, redirects are not the only way an URL can be mapped to a physical file on the webserver. To find which file is served or which file contains the code that is executed to produce what you receive, you first need to know which application server/framework is used, and learn how it works.

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

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?