How to get response from url using Javascript

I am making a request to break the phone, for this I will receive a response from this URL

http://www.apexweb.co.in/apex_quote/uname_validation.asp .

I don't know how to get the answer, can anyone help me with the code?

+3


source to share


2 answers


If your application needs to connect to another site, you can use JSONP

http://en.wikipedia.org/wiki/JSONP

That is, if you know that uname_validation.asp supports JSONP

If your page is on the same domain ( http://www.apexweb.co.in ) you can use xmlhttprequest.

Both are very lightweight and compatible with almost every browser using jQuery $ .getJSON:



http://api.jquery.com/jQuery.getJSON/

Here's an example of connecting to Google:

$(document).ready(function(){
    var url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q="
     +"someting&callback=?';
    $.getJSON(url, function(data){
        console.log(data);
    });
});

      

Note that your asp must have a response header that sets the contentType for the app / javascript and generates a valid JSONP (my asp is rusty, so here is some pseudocode):

request("callback")&"("&jsonString&");"

      

0


source


using ajax in javascript can get a response.



var invocation = new XMLHttpRequest();
var url = 'http://www.apexweb.co.in/apex_quote/uname_validation.asp';

function checkURL(){
        invocation.open('GET', url, true);
        invocation.onreadystatechange = handler;
        invocation.send(); 
}

function handler(evtXHR){
    if (invocation.readyState == 4)
    {
            if (invocation.status == 200)
            {
                //success
            }
            else {
                //failure
            }
    }
}

      

0


source







All Articles