简体   繁体   English

解析错误以响应AJAX调用

[英]Parse error in response of AJAX call

I am new to javascript and jquery, in my code I'm initiating a AJAX call and I get the following response. 我是javascript和jquery的新手,在我的代码中,我正在发起AJAX调用,并且得到以下响应。

在此处输入图片说明

I'm trying to implement an autocomplete functionality. 我正在尝试实现自动完成功能。 I am using below code to do AJAX call. 我正在使用以下代码进行AJAX调用。

$( "#city" ).autocomplete({
      source: function( request, response ) {
        jQuery.ajax({
          url: "the url",
          data: {SearchTerm: request.term}
          success: function (data) {
               console.log("the data is" +data); 
               response(data);
            }
        }).fail(function (jqXHR, textStatus, error) {
             console.log("failure1" + textStatus);
             console.log("failure2" + jqXHR.status);
    });
      },
      minLength: 3,
      select: function( event, ui ) {
        console.log( ui.item ?
          "Selected: " + ui.item.label :
          "Nothing selected, input was " + this.value);
      },
      open: function() {
        $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
      },
      close: function() {
        $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
      }
    });
  });

Even though I see 200 response from the server and the response in JSON format, success method doesn't get called and fail get called. 即使我看到来自服务器的200个响应和JSON格式的响应,也不会调用成功方法,而会调用失败方法。 Since I'm getting JSON response with 200 status, doesn't success method should get called? 由于我收到状态为200的JSON响应,因此不应该调用成功方法吗?

Try this, may be this will help you : 试试这个,也许这会为您提供帮助:

Option 1 : 选项1 :

May be you accidently turning On Magic Quotes in PHP 可能是您不小心在PHP中打开了魔术引号
But this function is already deprecated in PHP 5.3.0. 但是此功能已在PHP 5.3.0中弃用。
And REMOVED as of PHP 5.4.0. 从PHP 5.4.0开始删除。 as mentioned in here 正如这里提到的

  • Go to your php.ini file 转到您的php.ini文件
  • Search this keyword : magic_quotes_gpc 搜索此关键字: magic_quotes_gpc
  • Set it to OFF : magic_quotes_gpc = Off 将其设置为OFF: magic_quotes_gpc = Off

Option 2 : 选项2:

Do it on your code like this : 在您的代码上执行以下操作:

 if (get_magic_quotes_gpc()) { $returnedValue = stripslashes($yourReturnedValue); } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM