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 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分