N
N
Nikolay Baranenko2017-05-25 04:22:06
JavaScript
Nikolay Baranenko, 2017-05-25 04:22:06

What is the correct way to pass parameter to get JSON by URL?

Hello.

By sending ajax request to url trying to get json
works fine if done like this

http://localhost:8000/Forward?URL=dataset/employees.jsp?selected_region=Краснодар


trying to implement in javascript

$.getJSON( "Forward?URL=dataset/employees.jsp", { selected_region: selected } )
            .done(function( json ) {
                console.log("Список возможных позиций");
                console.log(json);
            })
            .fail(function( jqxhr, textStatus, error ) {
                var err = textStatus + ", " + error;
                console.log( "Request Failed: " + err );
            });


as a result
Request Failed: parsererror, SyntaxError: Unexpected token < in JSON at position 24


What is wrong and how to solve the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2017-05-25
@Stalker_RED

In the browser console, check what exactly is returned by the request. It looks like it's html instead of JSON.
And it’s better to add a leading slash to the address so that it works not only on the main one.
$.getJSON( "/Forward?URL=dataset/employees.jsp"...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question