2017-04-12 64 views
1

编写这段代码是为了将文件保存在文件txt中,我也会在调用按钮共享之后使用相同的代码。 我的问题来了,当我使用此代码已被传递到长的网址

$.ajax({ 
 
    url: "/condividi.php", 
 
    dataType: "json", 
 
    data: { 
 
    res: osrm_result 
 
    }, 
 
    success: function(data, textStatus, jqXHR) { 
 
    alert("ciaociao"); 
 
    window.open("https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2F52.16.81.189%2Findex_gen.html&src=sdkpreparse"); 
 
    } 
 
});

此触发器的错误:网址太长 如何,我可以纠正这种使它工作

+0

检查此:http://stackoverflow.com/questions/2891574/how-do-i-resolve-a-http-414-request-uri-too-long-error –

+0

目前还不清楚是否导致URL该错误是为ajax或window.open中的错误指定的错误。请澄清。 – Difster

+0

网址参数根本没有设计为包含大量信息。你应该使用POST。 –

回答

0

默认的方法,jQuery使用是数据长度有限的GET, 尝试通过POST发送数据(当然,您应该更新condividi.php以提供POST请求):

$.ajax({ 
    type: "POST", 
    url: "/condividi.php", 
    dataType: "json", 
    data: { 
    res: osrm_result 
    }, 
    success: function(data, textStatus, jqXHR) { 
    alert("ciaociao"); 
    window.open("https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2F52.16.81.189%2Findex_gen.html&src=sdkpreparse"); 
    } 
}); 
+0

ty picar与它的工作 –

+0

如果它在未来有所帮助,你可以对此答案进行投票,人们被引导到接受的答案 – Akintunde007