0

I have a php script, which return serialized in php data. And I try to receive this data by using $.ajax() method from jQuery 1.7. Here is the example.

$.ajax({
    url: 'http://input.name/get.php?do=lookup' + '&domain=twittorama&tlds=.ru,.com,.net,.comf.ru',
    type: 'GET',
    dataType: 'text',
    cache: 'false',
    complete: function(res) {
        alert('COMPLETE() done');
        console.log(res);
    }
});

In console I see only

Object { readyState=0, status=0, statusText="error"}

So, what I do wrong? Could you help me please?

UPD

Interesting notice: if I use JSONP dataType request can receive data, but can't process it. Here is an example.

$.ajax({
    url: 'http://input.name/get.php?do=lookup',
    data: 'domain=twittorama&tlds=.ru,.com,.net,.comf.ru',
    dataType: 'jsonp',
    cache: false,
    success: function(data) {
        alert("Data: "+data);
    },
    error: function(jqXHR, textStatus, errorThrown) {
        alert("Error: "+textStatus);
        console.log(jqXHR);
    }
});

3 Answers 3

2

Instead of complete: use success: then res will be the returned data from your ajax request.

Remember to use error: as well incase there is an error with you call, as it seems that there might be in your console output.

Code:

$.ajax({
    url: 'http://input.name/get.php?do=lookup',
    data: 'domain=twittorama&tlds=.ru,.com,.net,.comf.ru',
    cache: false,
    success: function(data) {
        alert("Data: "+data);
    },
    error: function(jqXHR, textStatus, errorThrown) {
        alert("Error: "+textStatus);
        console.log(jqXHR);
    }
});
Sign up to request clarification or add additional context in comments.

1 Comment

jsfiddle.net/q69sW/11 - it's the code with error processing - it doesn't show any details of error
2

Your code is probably fine, but you're trying to violate the same origin policy. Basically, if your site is http://aaa.com/, you cannot make AJAX called to http://bbb.com/.

There are a few ways around it:

But most of them require that both sides play nice.

7 Comments

but if it's the problem - why I don't receive any detailed error message from jQuery?
I'm not sure what you'r expecting, but I do see the following error message in my JS console: XMLHttpRequest cannot load http://input.name/get.php?do=lookup&domain=twittorama&tlds=.ru,.com,.net,.comf.ru. Origin http://fiddle.jshell.net is not allowed by Access-Control-Allow-Origin.
I've updated my answer - in dataType='jsonp' case request can receive the data...
Because it's not JSON. That's what I meant by both sides "playing nice".
I just want to say that it's not a policy problem if I see the data in console. So, I don't understand why I can't see the data and receive an error when I use 'text' dataType...
|
1

The response is the second parameter of complete function:

$.ajax({
    url: 'http://input.name/get.php?do=lookup' + '&domain=twittorama&tlds=.ru,.com,.net,.comf.ru',
    type: 'GET',
    dataType: 'text',
    cache: 'false',
    complete: function(res,response) {
        alert('COMPLETE() done');
        console.log(response);
    }
});

More info: http://api.jquery.com/jQuery.ajax/

You should also consider using JSON, not php serialized data

5 Comments

here is some problem - input.name is a service site, which provide only php-serialized data
I see this function. But before process this data, I should get it from remote host. I try to use your code - it logs "error" in console.
try using your browser console for debugging this. You should have more information about this request in firebug plugin (firefox) or developer console (chrome) - there are also detailed information about each ajax request
propably it's the same origin policy violation, but everything about this should be visible in developer console and debug info there
if I use console from Chrome and if I use 'jsonp' dataType I can see my data in it. but jquery can't process it right - because it's not a json data. so, it means that request can receive data in this case. but can't receive it, when using 'text' dataType. it's confusing me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.