简体   繁体   中英

Is it ok to use a non-existent url to make a AJAX call?

To contextualize:

I'm trying to use AJAX

$.ajax({
    url : "/logTest", // <- "false" url
    //url : "/log",   // <- "real"  url
    type : 'POST',
    success : function(result) {
        alert("send");
        console.log(result);
        // ifrm.document.open();
        // ifrm.document.write(data); // Escreve no iframe
        // ifrm.document.close();
        $("#content").html(result);

    }
});

to update, at each 'X' times, only one part of an HTML page ( <div> ). Before, I used the same URL to return my view and my object (resulted in several problems ). To avoid this, I created a "false" url for my object ( /logTest ) and kept the original url for the view ( /log ).

VIEW:

@RequestMapping(value = "/log", method = RequestMethod.POST)
    public String logContent_post(@Valid Log log, BindingResult bindingResult, Map<String, Object> model) {
          ...
    model.put("path", logsDir);
    model.put("log", log);
    model.put("currentPage", "logs");
    model.put("root", root);
return "log";
}

OBJECT:

@RequestMapping(value = "/logTest", method = RequestMethod.POST)
    @ResponseBody
    public String logContent_aux(@Valid Log log, BindingResult bindingResult, Map<String, Object> model) {
             ...
 return log.getContent();
}

The problem is that my expected object is returning as null and I do not know why.

Brower console: 插入图像的描述

My console:

\clearing-dit\logs\null (The system can not find the specified file)

So, my question is: is it wrong to use url's like this? Can my problem be derived from this or I'm missing somenting else?If I use my original url (/log) for the object, the object returns correctly. But, by doing this, I'm not able to return my view, because it's not possible to return two things with the same url, right?

Your question is pretty unclear . In your VIEW you are returning a string and in your OBJECT you are calling a function log.getContent() which is supposed to return a string as well and the code for the function is not found.

Also what is the status code you get when you use the wrong URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM