jqueryajax错误

jqueryajax错误,jquery,ajax,Jquery,Ajax,我正在使用jquery ajax检索一些数据,但它失败了,下面是代码: $.Webpic_Init = function(){ var type = 'default'; $.ajax({ url:SITE_PATH+"services/service.php?m=share&a=uploadwebpic&photo_type="+type, type: "POST", da

我正在使用jquery ajax检索一些数据,但它失败了,下面是代码:

 $.Webpic_Init = function(){
        var type = 'default';
        $.ajax({
            url:SITE_PATH+"services/service.php?m=share&a=uploadwebpic&photo_type="+type,
            type: "POST",
            data:{ name: "John", location: "Boston" },
            cache:false,
            dataType: "json",
            success:function(result){
                alert(result);
            },
            error:function(){
                alert('error');
            }
        });
    }
这会提醒“错误”。
但是,如果我将url参数更改为'SITE_PATH+“services/service.php',则会调度'success'事件。那么,如果我不想更改url参数,我该怎么办?

您正在发出POST请求,所有字段都应该像您所做的那样位于数据对象中

data:{ name: "John", location: "Boston" }

您不应该在url上放置任何内容。这是GET请求。

在url中预先添加
/
,而不是添加
站点路径。这将使URL相对于域,即相对于
www.your-domain.com/
。如果
服务
在某个子文件夹中,您可以像
/sub\u folder\u name/services/u path\u continue那样执行操作,这只是一个建议,请尝试使用以获得如下正确错误:

        var type = 'default';
        $.ajax({
            url: 'services/service.php',
            type: "POST", dataType: "json",
            data: { 'm': 'share', 'a': 'uploadwebpic', 'photo_type': type, 'typename': "John", 'location': "Boston" },
            //contentType: "application/json; charset=utf-8",
            cache: false,           
            success: function (data) {
                alert(result);
            }
        });
$(function() {
    $.ajaxSetup({
        error: function(jqXHR, exception) {
            if (jqXHR.status === 0) {
                alert('Not connect.\n Verify Network.');
            } else if (jqXHR.status == 404) {
                alert('Requested page not found. [404]');
            } else if (jqXHR.status == 500) {
                alert('Internal Server Error [500].');
            } else if (exception === 'parsererror') {
                alert('Requested JSON parse failed.');
            } else if (exception === 'timeout') {
                alert('Time out error.');
            } else if (exception === 'abort') {
                alert('Ajax request aborted.');
            } else {
                alert('Uncaught Error.\n' + jqXHR.responseText);
            }
        }
    });
});

这将帮助您正确处理Ajax错误,并获得在进行Ajax调用时发生的确切错误。

您是否可以使用chrome网络选项卡或FF的firebug网络选项卡监视请求,并检查出了什么问题,如响应代码等?,或者共享一个url,以便我们检查这是否可行。SITE_PATH的值是多少,它是否与此代码所在的页面位于同一域中?因此,您的基本意思是url不正确,如果您更改url,它会起作用,出于某种原因,如果你添加了一组新的引号,使你的变量成为URL的一部分,那么它实际上是有效的,但是你真正想知道的是,你能做些什么使它与你的URL一起工作?答案似乎很明显,更改文件的位置以匹配您的URL,或者更改URL以匹配文件的位置?每次我查看您的URL时,都会有一只小猫死亡。奇怪的是,它会在chrome网络选项卡中显示响应结果。但仍然会提醒“error”。似乎我需要将php数组转换为json格式;它是有效的。在post的service.php中放一个断点?然后查看它是否正在触发。url是内部路径还是外部路径?