Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi
I've this piece of code which suppose to get a json answer from a localhost site.
if I browse this url from chrome I get good response, but if I try to run this code from the html page I get error (via the VS debug).

Any ideas?
JavaScript
$(document).ready(function () {
        alert("hello");
        var request = $.ajax({
            url: "http://localhost:3157/api/Products",
            type: "GET",
            dataType: "json"
        });
        request.done(function(msg) {
            alert("msg is: " + msg);
        });
        request.fail(function (jqXhr, textStatus) {
            alert("Request failed: " + textStatus);
        });
    });
Posted
v2
Comments
Dholakiya Ankit 19-Jul-13 7:54am    
what error ??
Shahare 20-Jul-13 14:58pm    
The outcome is simply "error"
ZurdoDev 19-Jul-13 10:15am    
What is the error?
Shahare 20-Jul-13 14:59pm    
The outcome is simply "error"
ZurdoDev 20-Jul-13 17:27pm    
Look at the documentation for the .ajax, http://api.jquery.com/jQuery.ajax/, and use the error function.

1 solution

Found the solution here.
It appears I was for some reason blocked for Cross-Site scripting
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900