1

I'm using Umbraco, trying to follow the Base tutorial as shown on the website.

The following code gives me a syntax error in FireBug:

jQuery("#get").click(function() { 
        var pageId = <umbraco:Item field="pageID" runat="server" />;
          jQuery.get("/base/Sample/GetPageData/" + pageId + ".aspx", function(data){
            alert("Data loaded: " + jQuery(data).test());
          });
    });

I don't know if the umbraco code is causing the error but it is succesfully returning the pageId so the error reads as: Syntax Error: var pageId= 1007

Any ideas where I'm going wrong?

EDIT: Hope this helps clarify things, if not let me know!

Button I am setting up in umbraco template of page:

<asp:Button id="get" Text="getxml" runat="server" />

Although I have just realised that the rendered HTML of the button is a bit of a mess:

<input type="submit" name="ctl00$ctl00$ContentPlaceHolderDefault$get" value="getxml" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ctl00$ContentPlaceHolderDefault$get&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" id="ContentPlaceHolderDefault_get" />

Why is it doing this??

This is the jquery code as generated in the page:

 jQuery("#get").click(function()
        var pageId = '1082';
          jQuery.get("/base/Sample/GetPageData/" + pageId + ".aspx", function(data){
            alert("Data loaded: " + jQuery(data).test());
          });
    });

I included the enclosing single quotes as suggested but with or without I am getting the same Syntax Error in FireBug and my script is not working

1
  • Can you post the rendered output? Commented Dec 19, 2011 at 16:26

2 Answers 2

2

I think pageId is a string looking at your code so it should be enclosed in quotes. Try this.

jQuery("#get").click(function()
        var pageId = '<umbraco:Item field="pageID" runat="server" />';
          jQuery.get("/base/Sample/GetPageData/" + pageId + ".aspx", function(data){
            alert("Data loaded: " + jQuery(data).test());
          });
    });
Sign up to request clarification or add additional context in comments.

4 Comments

Can you check the source and see what is rendered on the page at that place?
Can you put alert('test get request') before your alert in the get success handler and see if it works.
The id of the button is not being set to what I defined in the template. Instead this id is given to the button 'ContentPlaceHolderDefault_Get' as well as a whole load of other generated stuff (see edit in question) - I guess umbraco is doing this. I had already tried test alerts and nothing is coming up, which now that I have discovered a re-generated idea for the button explains...
alert not working. nor is changing the button id to the generated id that i mentioned above..
0

button with the Id 'get' was being generated as ContentPlaceHolderDefault_Get for some reason (Umbraco?). So I changed the name in the get method to the generated name whilst leabing the button Id as get.

I guess this was a result of me writing the button control in an umbraco template rather than copying over from a .net control

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.