0

I am trying to write a script that gets COVID-19 numbers from the Ontario Database, but I keep getting the following error:

"invalid value \"_\""

Upon further investigation, the URL that is trying to be accessed contains the following parameter:

&_=1610496351832

As you can see in my code below, I never define such a variable:

    var data = {
      resource_id: '8a89caa9-511c-4568-af89-7f2174b4378c' // the resource id
    };
    $.ajax({
        dataType: 'jsonp',
        data: data,
        url: 'https://data.ontario.ca/api/3/action/datastore_search'
    });

Is there any way I can remove the _ object from the request?

The file I am trying to access is located at the following URL, where data is the resource_id.

https://data.ontario.ca/api/3/action/datastore_search?resource_id=8a89caa9-511c-4568-af89-7f2174b4378c
2
  • What is data? What produces the error? What appends the _ parameter? Commented Jan 13, 2021 at 0:43
  • It's the page where the data is located. I'll update the question to be more clear. Commented Jan 13, 2021 at 1:45

1 Answer 1

4

That is an automatic value generated by JQuery to avoid the cache.

Add the following to your script if you want to get rid of the underscore param:

    var data = {
      resource_id: '8a89caa9-511c-4568-af89-7f2174b4378c' // the resource id
    };
    $.ajax({
        dataType: 'jsonp',
        data: data,
        type:'GET',
        cache: true,
        url: 'https://data.ontario.ca/api/3/action/datastore_search'
    });

It only occurs in GET requests, you can play around with this setting. But remember, the automatic underscore param is included intentionally to avoid the request cashing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.