通过URL作为后数据时,jQuery的AJAX返回404错误 [英] jQuery ajax returning 404 error when passing URL as post data

查看:744
本文介绍了通过URL作为后数据时,jQuery的AJAX返回404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 $。阿贾克斯得到一个404错误,并且已经把范围缩小的问题是与我传递数据的值之一。

我想传递一个URL文本保存到我的数据库。

  $。阿贾克斯({
    键入:POST,
    网址:'ajax.php,
    数据:{编辑 - 用户名:用户名,网站的价值:websiteValue}
})。完成(功能(){
    //定制code在这里
});
 

如果我设置 websiteValue 等于 http://google.com ,然后我得到一个404错误的铬合金的网络选项卡。 (这是适用于任何其他比我自己的域名。)

如果我将它设置为//google.com或只是google.com它工作正常。

如果我将它设置为 http://mydomain.com 也伟大工程。

我不明白这一个和任何帮助将大大AP preciated。 Ajax调用正在完成通过HTTPS,如果有什么差别。

该ajax.php文件如何处理数据如下。

  $ mysqli的= connect_db();
$查询= $ mysqli-> prepare(更新TBL设置网站=其中username =?');
$查询 - > bind_param('SS',$网站,$的用户名);
$查询 - >执行();
$查询 - >关闭();
$ mysqli->关闭();
 

解决方案

我觉得这是服务器响应。服务器尝试prevent跨域攻击。什么是服务器日志?服务器是什么?

I have been getting a 404 error when using $.ajax and have narrowed it down to the problem being with one of the values I am passing with data.

I am trying to pass a url as text to be saved to my database.

$.ajax({
    type: 'POST',
    url: 'ajax.php',
    data: {'edit-username': username, 'website-value': websiteValue}
}).done(function(){
    //custom code here
});

If I set websiteValue equal to http://google.com, Then I get a 404 error on chromes network tab. (this is true for anything other than my own domain.)

If I set it to //google.com or just google.com it works fine.

If I set it to http://mydomain.com it also works great.

I can't figure this one out and any help would be greatly appreciated. The ajax calls are being done over https if that makes any difference.

The ajax.php file does the following with the data.

$mysqli = connect_db();
$query = $mysqli->prepare('UPDATE tbl SET website = ? WHERE username = ?');
$query->bind_param('ss', $website, $username);
$query->execute();
$query->close();
$mysqli->close();

解决方案

I think it is server response. Server try to prevent cross-domain attack. What is in server logs? What is the server?

这篇关于通过URL作为后数据时,jQuery的AJAX返回404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆