3

I have an HTML file with the URL localhost/dir1/dir2/file.html. In this file I send data through jquery to the server.

$('#element').live("change", function(){
    $.ajax({
        url:  "localhost/dir1/dir3/file.php",
        type: "POST",
        data: { esp: $(this).val() },
        success: function(result){
            $("#element2").html(result);
        }
    })

I get an error due to jquery send the data to localhost/dir1/dir2/localhost/dir1/dir3/file.php but I need send the data to localhost/dir1/dir3/file.php. How can I do this?

4

1 回答 1

5

将您的网址更改为:

   /dir1/dir3/file.php

这避免了将协议和服务器硬编码到您的代码中。

于 2013-05-09T19:20:56.233 回答