0

I'm trying to use ajax to send back a string var from ProParty.php and load it into the tag ID "PartyTitle". However I'm getting this error:

Uncaught SyntaxError: Unexpected identifier

On this line: context: document.getElementById("PartyTitle").innerHTML

Here is the ajax that loads with the body of the document:

$.ajax({
      url: "ProParty.php",
      data: { Action: "Load", loadWhat : "PartyName" , PartyId: "1" },
      type: "GET",
      context: document.getElementById("PartyTitle").innerHTML
    }).done(function() {

    });

Here is the HTML tag that I want to edit/fill.

<h2><p id= "PartyTitle"> Editing Your Party  </h2>
8
  • 5
    missing the comma after "GET" Commented Jun 19, 2014 at 17:25
  • Check here jshint.com Commented Jun 19, 2014 at 17:26
  • 3
    BTW, what are you expecting passing a string as context to do? Commented Jun 19, 2014 at 17:27
  • @KennyThompson okay got that Commented Jun 19, 2014 at 17:27
  • 1
    context should be a plain object, not a string. Reference Commented Jun 19, 2014 at 17:31

2 Answers 2

2

You are missing a comma after "GET" on the previous line. The following should work:

$.ajax({
  url     : "ProParty.php",
  data    : { Action: "Load", loadWhat : "PartyName" , PartyId: "1" },
  type    : "GET",
  context : document.getElementById("PartyTitle").innerHTML
}).done(function() {

});

*Edit to answer your question in the above comments

$.ajax({
  url     : "ProParty.php",
  data    : { Action: "Load", loadWhat : "PartyName" , PartyId: "1" },
  type    : "GET",
  success : function (data) {
    $('#PartyTitle').html(data);
  }
});

-- with load ( http://api.jquery.com/load/ ) --

$('#PartyTitle').load('ProParty.php', { Action: "Load", loadWhat: "PartyName", PartyId: "1" });
Sign up to request clarification or add additional context in comments.

9 Comments

+1 I understand question like that too, even you could use load() instead, which exists for this exact purpose. That's said, passing data as object to load() make it request of type POST
You would be using less code. It sounds like it calls ajax in the background anyways. See: forum.jquery.com/topic/jquery-load-vs-jquery-ajax and stackoverflow.com/questions/1246137/…
Ya, load() is a shorthand for some ajax request, setting content on matched element
@KennyThompson I just started playing with ajax yesterday so I'm really limping along. I know its a lot but could you rewrite this to use load() so that I can see how it transfers over?
Thank you Very much! Is there some way that I can give you some extra points or something?
|
1

According to the API documentation, context should be a plain object not a string.

Change your code like so:

$.ajax({
  url: "ProParty.php",
  data: { Action: "Load", loadWhat : "PartyName" , PartyId: "1" },
  type: "GET",
  context: document.getElementById("PartyTitle")
}).done(function() {
    // Reference the element as $(this)...
});

Reference: jQuery.ajax()

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.