意外令牌LT;读取XML文件 [英] Unexpected token < reading xml file

查看:123
本文介绍了意外令牌LT;读取XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,当我做一个AJAX调用。

I'm having a problem when i do an ajax call.

我的code是:

$('#regLink').click(function(event){
  event.preventDefault();
  urlLink = $('#regLink').attr('name') + $('input[name="email"]').val();
  $.ajax({
    type: 'GET',
    dataType: 'jsonp',
    jsonpCallback: 'callback',
    url: urlLink,
    success: function (xml) {
      var code = $(xml).find('int').text();
      if(code == '1') {
        console.log('email gravado com sucesso');
      }
      else {
        console.log('algo correu mal');
      }
    }
  });
});

通话给这个回应:

The call give this response :

<?xml version="1.0" encoding="utf-8"?> 
<int xmlns="http://tempuri.org/">1</int>

和它给我这个错误:

Uncaught SyntaxError: Unexpected token <

URL指向其他网站,因此它的跨域调用。

The URL points to another site, so its a cross domain call.

我只是想读的1,并给了成功的警报。

I just want to read the "1" and give a success alert.

希望你能帮助我。

感谢

推荐答案

您的JavaScript说做一个Ajax请求使用JSONP模式(其中包括把&LT;脚本SRC =东西&GT; 元素插入文档,而不是使用XMLHtt prequest)。

Your JavaScript says to make an Ajax request using the JSONP pattern (which involves inserting a <script src="something"> element into the document instead of using XMLHttpRequest).

你得到的响应是一个XML文档,不继JSONP模式的JavaScript程序,这将是这样的:

The response you are getting is an XML document, not a JavaScript program following the JSONP pattern, which would be something like:

value_of_query_string_callback_argument({ "int": 1 });

您得到的错误,因为浏览器尝试执行XML作为JavaScript的(它不是)。

You get the error because the browser is trying to execute the XML as JavaScript (which it isn't).

无论是改变响应是JSONP,或使用一些其他的方法,使跨域请求

Either change the response to be JSONP, or use some other method to make a cross-domain request.

这篇关于意外令牌LT;读取XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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