The problem could be that you are referencing the second element with the [1], jquery collection is zero index based. Also try to put a debugger; keyword just before the problematic line or using Chrome Developer tools to debug your script. I think this
is not a problem in your Ajax call but is a javascript error that is throwing an error (exception). you can put this code in a try/catch block as well.
debugger;
var pageNum = $("a.weather").attr("href").match(/page=([0-9]+)/)[0];
Please remember to mark as Answer if the post helps you out.
Marked as answer by CareerChange on Feb 06, 2013 04:02 PM
CareerChange
Member
43 Points
180 Posts
2nd Parameter breaks partial page update
Feb 05, 2013 10:18 PM|LINK
Hi
Does anyone know why when adding the 2nd parameter to the ajax code below, it breaks my partial page update
$(function () { $(".getCities").click(function () { var city = $(this).text(); //var pageNum = $("a.weather").attr("href").match(/page=([0-9]+)/)[1]; $.ajax({ url: '@Url.Action("pvDisplayListOfWeatherCities", "Weather")', type: 'GET', //data: { id: $(this).attr("data-param1"), p: pageNum }, data: { id: $(this).attr("data-param1")}, dataType: 'html', success: function (result) { $('Title').text('Cities in ' + city), $('#dvFullPage').remove(); $('#dvPartial').html(result); }, error: function () { alert("error"); } }); return false; }); });Adding this line breaks the code.
var pageNum = $("a.weather").attr("href").match(/page=([0-9]+)/)[1];
Thanks
George
asteranup
All-Star
30184 Points
4906 Posts
Re: 2nd Parameter breaks partial page update
Feb 06, 2013 08:41 AM|LINK
Hi,
Put a detailed error method in the ajax call and then debug the problem-
https://delicious.com/anupdg/error+pagemethod
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
Talal Tayyab
Participant
902 Points
132 Posts
Re: 2nd Parameter breaks partial page update
Feb 06, 2013 12:23 PM|LINK
Hi,
The problem could be that you are referencing the second element with the [1], jquery collection is zero index based. Also try to put a debugger; keyword just before the problematic line or using Chrome Developer tools to debug your script. I think this is not a problem in your Ajax call but is a javascript error that is throwing an error (exception). you can put this code in a try/catch block as well.
debugger; var pageNum = $("a.weather").attr("href").match(/page=([0-9]+)/)[0];