Skip to content Skip to sidebar Skip to footer

How To Feed A Url With A / To A Javascript Object?

I have a simple AJAX/JavaScript function which makes a GET request and loads a page into the current page based on a URL if successful: function loadDoc(myUrl) {

Solution 1:

I thought it was an issue with the quotes

It is.

You are trying to write a string literal without any.

onclick="loadDoc("/myUrl/toTheLocalSever")">
var wrappedUrl = "'"+myUrl+"'"

You can't fix a syntax error from code that runs after the error has been thrown.

Solution 2:

i believe the error is in your function call

<lionclick="loadDoc(/myUrl/toTheLocalSever)">Add Dataset to View</li>

should be

<lionclick="loadDoc('/myUrl/toTheLocalSever')">Add Dataset to View</li>

in your version its passing as variable /myUrl/toTheLocalSever which does not exist is regular expression syntax

Post a Comment for "How To Feed A Url With A / To A Javascript Object?"