0

I need to extract the value of studentId just 1413 how could this be done?
All this code below is stored in a single variable I think with regex it is possible but had no luck with it

$(document).ready(function () {
        var getSchedule = function () {
            $.ajax({
                type: 'GET',
                url: "Schedule",
                data: {
                    "studentId": 1413,
                    "term": $("#Term").val(),
                    "academicYear": ,
                    "docId": $("#DocId").val()
                },
                beforeSend: function () {
                    $('#contentArea').html('<center><img src="../../Content/images/ajax-loader.gif" alt="loading"/></center>');
                },
                success: function (data) {
                    $("#contentArea").html(data);
                },
                dataType: "html",
                error: function () {
                    alert("Error");
                }
            });
        }

Edited by lttleastig

4
Contributors
7
Replies
35
Views
4 Years
Discussion Span
Last Post by pixelsoul
0

no this data is in a variable so it is one long string i think i need some sort of preg_match but i can't seem to find the right combination of symbols

0

Your comment and code do not make any sense.

I need to extract the value of studentId just 1413 how could this be done?

Then

data: {
    "studentId": 1413,
    "term": $("#Term").val(),
    "academicYear": ,
    "docId": $("#DocId").val()
},

So first idea is that you want to pick up $_GET['studentId'], but then you say...

no this data is in a variable so it is one long string i think i need some sort of preg_match but i can't seem to find the right combination of symbols

Why didn't you just post the long string and tell us which bits of data you need to extract? Posting the ajax code was unnecessary, if I'm understanding you correctly.

0

That code is what is in the string. the data i need to extract is the value 1413

0

So the code posted is the string. Ok got it now.

preg_match('/"studentId": (\d+)/', $str, $matches);
echo $matches[1];

Maybe

0

I'm real curious on how you are storing that in a string. You have a mixture of double and single quotes in it. Are you escaping everything? diafol's regex would work but there is something that we are not seeing here.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.