Jquery ajax请求在chrome上失败

时间:2022-12-01 10:55:24

i have to make an ajax request to a PHP file to update the database. The PHP file should be called when i click on a link. Here's the jquery code i use:

我必须向PHP文件发出ajax请求以更新数据库。单击链接时应调用PHP文件。这是我使用的jquery代码:

$("a#email_contatti").click(function(){
   $.get("/segna_mail.php",{sito:'mywebsite'});
});

It works fine on Firefox 4/5 and Safari..But Chrome ( v14.0.797.0 but it does not work also on other versions) seems to cut the request and it does not update the db.. I tried also to access the PHP script via url and there it works fine also on Chrome.. Someone told me to add the return false at the end of the function. Tried also this but it breaks the link ( it's a mailto link ). I have no more ideas..

它适用于Firefox 4/5和Safari ..但Chrome(v14.0.797.0,但它在其他版本上也不起作用)似乎削减了请求并且它没有更新数据库..我也尝试访问通过url的PHP脚本,它在Chrome上工作正常..有人告诉我在函数结束时添加返回false。也试过这个,但它打破了链接(这是一个mailto链接)。我没有更多的想法..

Thanks, Andrea

谢谢,安德烈

1 个解决方案

#1


0  

GET is meant to perform an operation that retrieves data, POST is meant to send data to a server (and most probably do something with it, like a database INSERT). So I imagine that Chrome may be cutting off / not sending the JSON data you're providing.

GET用于执行检索数据的操作,POST用于将数据发送到服务器(并且很可能用它做一些事情,比如数据库INSERT)。因此,我认为Chrome可能会切断/不发送您提供的JSON数据。

From what I take of what you're trying to do, it's better for you to use POST anyway. Try it out if that works.

从我对你想要做的事情来看,最好还是使用POST。如果有效,请尝试一下。

If you really want to try it out with GET, try $.get('/segna_mail.php?sito=mywebsite') instead.

如果你真的想用GET试试,试试$ .get('/ segna_mail.php?sito = mywebsite')。

#1


0  

GET is meant to perform an operation that retrieves data, POST is meant to send data to a server (and most probably do something with it, like a database INSERT). So I imagine that Chrome may be cutting off / not sending the JSON data you're providing.

GET用于执行检索数据的操作,POST用于将数据发送到服务器(并且很可能用它做一些事情,比如数据库INSERT)。因此,我认为Chrome可能会切断/不发送您提供的JSON数据。

From what I take of what you're trying to do, it's better for you to use POST anyway. Try it out if that works.

从我对你想要做的事情来看,最好还是使用POST。如果有效,请尝试一下。

If you really want to try it out with GET, try $.get('/segna_mail.php?sito=mywebsite') instead.

如果你真的想用GET试试,试试$ .get('/ segna_mail.php?sito = mywebsite')。