How to flip url back to query builder

I am using the OData query jQ library library to create adhoc reports and save them to the database using the generated OData strong> URL for the report along with it.

The above works fine - clients can select tables, conditions and filters there to create adhoc reports and save them to the database.

Problem

When my client returns to viewing the generated reports, I can request JSON data using the report URL, but I'm not sure how to select or add the tables, conditions and filters that they selected for this particular report.

eg. The report URL may be as simple as this,

1 -  www.example.com/Table1&$format=json  // this will return a simple table

In the above example, I can use JS to get the first table name "Table1" in this script and select it in the query builder.

But for complex URLs ... like

http://services.odata.org/Northwind/Northwind.svc/Customers ? $ filter = replace (CompanyName, '', '') eq 'AlfredsFutterkiste'

It's too hard to parse it back into HTML.

Request Time

How can I translate the URLs back to HTML to select the selected user table, conditions and filters they added, etc. (preferably using the JS library, which I mentioned at the beginning)

, HTML URL-, , , .

, , URL

enter image description here

+4
2

, .

:

, . URL- . , , URL-, , , ( , ).

,

- URL- - , , , , .

,

"url" . , , URL- , .

URL-, , , URL-. (, * generate_reports, url = 'queryUrl')

( )

localstorage:

:

var assigned_fields = {
    tables_selected: ["user", "cats", "dogs"]
}
var report_url = "http://not-really.com"
window.localStorage.setItem("report_"+report_url, JSON.stringify(assigned_fields))

function getAssignedFieldsFromURL(url) {
    return JSON.parse(window.localStorage.getItem("report_"+url))
}

, javascript , :

getAssignedFieldsFromURL("http://not-really.com")

.

, .

javascript GUI . , , .

URL

: URL- Javascript?

, URL-

function getJsonFromUrl(str) {
    var query

    var pos = str.indexOf("?")

    if (pos !== -1)
        query = str.substr(pos+1)

    else
        query = str

    var result = {}
    query.split("&").forEach(function(part) {

        if (!part)
            return
        part = part.split("+").join(" ") // replace every + with space, regexp-free version

        var eq = part.indexOf("=")
        var key = eq>-1 ? part.substr(0,eq) : part
        var val = eq>-1 ? decodeURIComponent(part.substr(eq+1)) : ""

        var from = key.indexOf("[")

        if (from == -1)
            result[decodeURIComponent(key)] = val
        else {
            var to = key.indexOf("]")
            var index = decodeURIComponent(key.substring(from+1,to))
            key = decodeURIComponent(key.substring(0,from))
            if(!result[key]) result[key] = []
            if(!index) result[key].push(val)
            else result[key][index] = val
        }
    })
    return result
}

:

getJsonFromUrl("http://google.com?test=5&cat=3")

: Object {test: "5", cat: "3" }

: , . , "+" "" .

0

, url, URL-, , .

, , .

var form = document.createElement("form");
var element1 = document.createElement("input");

form.method = "POST";
form.action = "Yourpage";             element1.value=document.getElementById("You input valueid").value;
element1.name="Your field in posted form";
form.appendChild(element1);  
document.body.appendChild(form);

form.submit();
-1

All Articles