最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Unexpected token < reading xml file - Stack Overflow

programmeradmin1浏览0评论

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

My code is :

$('#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  sucesso');
      }
      else {
        console.log('algo correu mal');
      }
    }
  });
});

The call give this response :

<?xml version="1.0" encoding="utf-8"?> 
<int xmlns="/">1</int>

And it give me this error :

Uncaught SyntaxError: Unexpected token <

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

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

Hope you can help me.

Thanks

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

My code is :

$('#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  sucesso');
      }
      else {
        console.log('algo correu mal');
      }
    }
  });
});

The call give this response :

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

And it give me this error :

Uncaught SyntaxError: Unexpected token <

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

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

Hope you can help me.

Thanks

Share Improve this question edited Nov 13, 2013 at 14:22 Rafael Mateus asked Nov 12, 2013 at 16:11 Rafael MateusRafael Mateus 433 silver badges10 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

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).

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 });

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

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

发布评论

评论列表(0)

  1. 暂无评论