Make a ajaxcall from my js(local apache) to an asp page (local iis)

81 Views Asked by At

I was wondering if any one can help me. It's so simple but I can't figure it out.

There is my js (in my .js)

$("#ajust-item").on("click", function(el){  
    el.preventDefault();
    $.ajax({  
        url: "http://localhost/Local-Site-A/test_ajax.asp",  
        dataType: "jsonp",  
        success: function(data) {
            console.log(data);
        }  
    });  
});

There is my ASP file :

<% response.write("test"); %>

Finally, there is the error than the Browser show me:

Resource interpreted as Script but transferred with MIME type text/html: "http://hostlocal/Local-Site-A/test_ajax.asp?callback=jQuery1102002555891638621688_1378843001887&_=1378843001888".

And if I click on that link, I see the word "test".

How can I json encode my data in my ASP file to have the good type for the answer etc. Can any one help me with this?


I did try this way to, and it doesn't work. js:

$.get('http://localhost/Local-Site-A/test_ajax.asp', function(response) { console.log(response); });

asp:

<%Response.AppendHeader("Access-Control-Allow-Origin", "*");
response.write("bravo")%>

Error :

XMLHttpRequest cannot load http://hostlocal/Local-Site-A/test_ajax.asp. Origin http://hostlocal:8080 is not allowed by Access-Control-Allow-Origin.

1

There are 1 best solutions below

0
On

In the asp file :

Call response.AddHeader("Access-Control-Allow-Origin", "*")
    response.write("bravo")

And it work well. With this line in the js :

$.get('http://localhost/Local-Site-A/test_ajax.asp', function(response) { console.log(response); });