I use js sdk to get data from facebook, I need to post this data to the server. and depending on this data I want to show something to the user.
if I use ajax I can't update sever text fields (and cant show the user the correct message).
is there a way to use ajax and to update a specific text box on the page?
$.ajax({
type: "POST",
url: 'myurl.aspx',
data: "id=" + id
});
on the load event of the page on the server side i have
If Not IsPostBack Then
Dim id As String = Request.Form("id")
If String.IsNullOrEmpty(id) Then
Else
Dim counter As Integer = 0
Dim code As String = ""
Dim flag As Boolean = True
If gotCode(id) Then
result.InnerHtml = "got already!"
Else
code = generateCode()
saveCodeInDB(code, id)
result.InnerHtml = code
End If
End If
End If
Jquery ajax has a setting method "success" that is called if the request succeeds, one of the parameters is the data returned from the server. You can return the data from the server and than update the html in jquery. For example:
You could also call the page from JavaScript but do not use Ajax. Just redirect to the page:
window.location.href = "myurl.aspx?id=" + id;
Then in the page behind for myurl.aspx get the data using the id (which it looks like you are doing) but instead of putting it on the response, just populate the values of textboxes or other controls on the page.
it's a great idea, no need for post, but in such a case I get into an endless loop. when the page is loaded again it try to retrieve the facebook id of the user again. and refresh again.
elic05
Member
38 Points
79 Posts
posting data from js to server and updating a server textfield on the same page
Feb 03, 2013 11:47 AM|LINK
I use js sdk to get data from facebook, I need to post this data to the server. and depending on this data I want to show something to the user.
if I use ajax I can't update sever text fields (and cant show the user the correct message).
is there a way to use ajax and to update a specific text box on the page?
$.ajax({ type: "POST", url: 'myurl.aspx', data: "id=" + id });on the load event of the page on the server side i have If Not IsPostBack Then Dim id As String = Request.Form("id") If String.IsNullOrEmpty(id) Then Else Dim counter As Integer = 0 Dim code As String = "" Dim flag As Boolean = True If gotCode(id) Then result.InnerHtml = "got already!" Else code = generateCode() saveCodeInDB(code, id) result.InnerHtml = code End If End If End IfTalal Tayyab
Participant
892 Points
132 Posts
Re: posting data from js to server and updating a server textfield on the same page
Feb 03, 2013 12:41 PM|LINK
Jquery ajax has a setting method "success" that is called if the request succeeds, one of the parameters is the data returned from the server. You can return the data from the server and than update the html in jquery. For example:
$.ajax({ url: url, type: "GET", dataType: "html", success: function (result) { $('#spanDetails').html(result); }, error: function (xhr, ajaxOptions, thrownError) { alert(thrownError); } });Look at JQuery Ajax: http://api.jquery.com/jQuery.ajax/
RichardY
Star
8376 Points
1573 Posts
Re: posting data from js to server and updating a server textfield on the same page
Feb 03, 2013 01:27 PM|LINK
You could also call the page from JavaScript but do not use Ajax. Just redirect to the page:
window.location.href = "myurl.aspx?id=" + id;
Then in the page behind for myurl.aspx get the data using the id (which it looks like you are doing) but instead of putting it on the response, just populate the values of textboxes or other controls on the page.
elic05
Member
38 Points
79 Posts
Re: posting data from js to server and updating a server textfield on the same page
Feb 03, 2013 09:02 PM|LINK
it's a great idea, no need for post, but in such a case I get into an endless loop. when the page is loaded again it try to retrieve the facebook id of the user again. and refresh again.
asteranup
All-Star
30184 Points
4906 Posts
Re: posting data from js to server and updating a server textfield on the same page
Feb 04, 2013 04:49 AM|LINK
Hi,
You can check many working example here-
https://delicious.com/anupdg/pagemethod
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog